package org.jsola.hr.service.impl;

import cn.hutool.core.date.StopWatch;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.jsola.admin.entity.DictItemDO;
import org.jsola.admin.entity.SiteDO;
import org.jsola.admin.query.HeaderFieldsQuery;
import org.jsola.admin.vo.HeaderFieldsListVO;
import org.jsola.admin.vo.SiteVO;
import org.jsola.common.*;
import org.jsola.core.Page;
import org.jsola.exception.ParamException;
import org.jsola.file.vo.BankCardInfoVO;
import org.jsola.hr.common.BeanCopyUtil;
import org.jsola.hr.common.EmpFieldModuleCodeKit;
import org.jsola.hr.common.ExampleKit;
import org.jsola.hr.common.HrLogKit;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.constant.PersonalEventEnum;
import org.jsola.hr.dao.ICompanyEmpNecessaryDAO;
import org.jsola.hr.dao.ICompanyNecessaryFieldDAO;
import org.jsola.hr.dto.*;
import org.jsola.hr.dto.excel.EmpImportSocRelatedDTO;
import org.jsola.hr.entity.*;
import org.jsola.hr.provider.*;
import org.jsola.hr.query.CompanyAdditionalFieldsQuery;
import org.jsola.hr.query.CompanyNecessaryFieldQuery;
import org.jsola.hr.query.EmpAdditionalFieldsQuery;
import org.jsola.hr.query.ModuleFieldQuery;
import org.jsola.hr.service.*;
import org.jsola.hr.service.async.IAsyncEmpInfoDetailService;
import org.jsola.hr.service.notice.ISendNoticeService;
import org.jsola.hr.vo.*;
import org.jsola.user.core.TokenUser;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.jsola.hr.constant.HrConstants.JIA_FANG_QY;
import static org.jsola.hr.constant.HrConstants.JIA_FANG_SY;

/**
 * 公司员工必填字段信息
 *
 * @author zhr
 */
@Slf4j
@Service("hrCompanyNecessaryFieldServiceImpl")
public class CompanyNecessaryFieldServiceImpl implements ICompanyNecessaryFieldService {

    @Autowired
    private ICompanyNecessaryFieldDAO companyNecessaryFieldDAO;

    @Autowired
    private ICompanyAdditionalFieldsService companyAdditionalFieldsService;

    @Autowired
    private IEmpAdditionalFieldsService empAdditionalFieldsService;

    @Autowired
    private IPersonalEventService personalEventService;

    @Lazy
    @Autowired
    private IEmpInfoService empInfoService;

    @Lazy
    @Autowired
    private IEmpFamilyService empFamilyService;

    @Lazy
    @Autowired
    private IEmpWorkService empWorkService;

    @Lazy
    @Autowired
    private IEmpEducationService empEducationService;

    @Lazy
    @Autowired
    private IEmpContactsService empContactsService;

    @Lazy
    @Autowired
    private IEmpTrainService empTrainService;

    @Lazy
    @Autowired
    private ICompanyEmpNecessaryService companyEmpNecessaryService;

    @Autowired
    private ICompanyEmpNecessaryDAO companyEmpNecessaryDAO;

    @Autowired
    private INoticeProviderService noticeProviderService;

    @Autowired
    private IUserProviderService userProviderService;

    @Autowired
    private ISiteConfigProviderService siteConfigProviderService;

    @Autowired
    private IMessageProviderService messageProviderService;

    @Autowired
    private ICompanyService companyService;

    @Autowired
    private ISendNoticeService sendNoticeService;

    @Autowired
    private IEmpSocRelatedService empSocRelatedService;

    @Autowired
    private IChannelService channelService;

    @Autowired
    private IAdminProviderService adminProviderService;

    @Autowired
    private IEmpRewardPunishService empRewardPunishService;

    @Autowired
    private ICustomTemplateFieldService customTemplateFieldService;

    /**
     * 初始化员工必填字段信息次数
     */
    private int initializationNum = 0;
    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private IFileProviderService fileProviderService;

    @Autowired
    private IAsyncEmpInfoDetailService asyncEmpInfoDetailService;

    /**
     * 工资卡信息code
     */
    private static final String SALARY_CARD_CHANGE_MODULE_CODE = "bank";
    /**
     * 员工备注
     */
    private static final String MODULE_REMARK = "remark";
    /**
     * 员工标签
     */
    private static final String MODULE_TAG = "tag";
    /**
     * 身份证信息code
     */
    private static final String MODULE_CODE_EMPIDCARD = "empIdCard";
    /**
     * 身份证信息名称
     */
    private static final String MODULE_NAME_EMPIDCARD = "身份证信息";
    /**
     * 工资卡信息code
     */
    private static final String MODULE_CODE_BANK = "bank";
    /**
     * 工资卡信息名称
     */
    private static final String MODULE_NAME_BANK = "工资卡信息";
    /**
     * 签发机关code
     */
    private static final String FIELD_CODE_ISSUEDBY = "issuedBy";
    /**
     * 签发机关名称
     */
    private static final String FIELD_NAME_ISSUEDBY = "签发机关";
    /**
     * 开始期限code
     */
    private static final String FIELD_CODE_STARTDATE = "cardStartDate";
    /**
     * 开始期限
     */
    private static final String FIELD_NAME_STARTDATE = "开始期限";
    /**
     * 结束期限code
     */
    private static final String FIELD_CODE_ENDDATE = "cardEndDate";
    /**
     * 结束期限
     */
    private static final String FIELD_NAME_ENDDATE = "结束期限";
    /**
     * 支付宝账号code
     */
    private static final String FIELD_CODE_ALIPAY_ACCOUNT = "alipayAccount";
    /**
     * 支付宝账号
     */
    private static final String FIELD_NAME_ALIPAY_ACCOUNT = "支付宝账号";

    /**
     * 工作性质
     */
    public static final String POST_TYPE = "POST_TYPE";

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int addFiledForAllCompany(CompanyNecessaryFieldAddDTO companyNecessaryFieldAddDTO, TokenUser tokenUser) {
        int sum = 0;
        if ("all".equals(companyNecessaryFieldAddDTO.getCompanyId())) {
            //获取用工单位
            List<String> companyIdList = companyNecessaryFieldDAO.selectAllCompanyId();
            log.info("共为{}个公司添加字段", companyIdList.size());
            //开始增加
            for (String companyId : companyIdList) {
                if (StrKit.isNotEmpty(companyId)) {
                    List<CompanyNecessaryFieldDO> companyNecessaryFieldDOS = selectByCompanyIdNotSiteId(companyId);
                    if (CollectionKit.isNotEmpty(companyNecessaryFieldDOS)) {
                        Example example = new Example(CompanyNecessaryFieldDO.class);
                        example.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("fieldCode", companyNecessaryFieldAddDTO.getFieldCode());
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOS1 = companyNecessaryFieldDAO.selectByExample(example);
                        if (CollectionUtils.isEmpty(companyNecessaryFieldDOS1)) {
                            tokenUser.setSiteId(companyNecessaryFieldDOS.get(0).getSiteId());
                            companyNecessaryFieldAddDTO.setCompanyId(companyId);
                            companyNecessaryFieldAddDTO.setSort(companyNecessaryFieldDOS.size() + 2);
                            save(companyNecessaryFieldAddDTO, tokenUser);
                            sum++;
                        }
                    }
                }
            }

        }
        return sum;
    }

    private List<CompanyNecessaryFieldDO> selectByCompanyIdNotSiteId(String companyId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("companyId", companyId);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public CompanyNecessaryFieldVO save(CompanyNecessaryFieldAddDTO companyNecessaryFieldAddDTO, TokenUser tokenUser) {
        // 转DO
        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldAddDTO.to(CompanyNecessaryFieldDO.class);
        // 保存
        companyNecessaryFieldDO = save(companyNecessaryFieldDO, tokenUser.getSiteId(), tokenUser.getUserId());
        return companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public List<CompanyNecessaryFieldVO> batchSave(List<CompanyNecessaryFieldAddDTO> companyNecessaryFieldAddDTOList, TokenUser tokenUser) {
        if (CollectionUtils.isEmpty(companyNecessaryFieldAddDTOList)) {
            return null;
        }
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldAddDTOList
                .parallelStream()
                .map(companyNecessaryFieldAddDTO -> {
                    CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldAddDTO.to(CompanyNecessaryFieldDO.class);
                    companyNecessaryFieldDO.preInsert(tokenUser.getUserId());
                    companyNecessaryFieldDO.setSiteId(tokenUser.getSiteId());
                    return companyNecessaryFieldDO;
                }).collect(Collectors.toList());
        companyNecessaryFieldDAO.insertListAndSetId(companyNecessaryFieldDOList);
        return companyNecessaryFieldDOList
                .parallelStream()
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class))
                .collect(Collectors.toList());
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int update(CompanyNecessaryFieldUpdateDTO companyNecessaryFieldUpdateDTO, TokenUser tokenUser) {
        CompanyNecessaryFieldVO companyNecessaryFieldVO = selectById(companyNecessaryFieldUpdateDTO.getId(), tokenUser.getSiteId());
        if (null == companyNecessaryFieldVO) {
            return 0;
        }
        //从open的开启到关闭
        if (companyNecessaryFieldVO.getIsOpen() && !companyNecessaryFieldUpdateDTO.getIsOpen()) {
            companyNecessaryFieldUpdateDTO.setIsNecessary(false);
        }
        //从open的关闭 到修改或者必填的开启
        if (!companyNecessaryFieldVO.getIsOpen() &&
                (companyNecessaryFieldUpdateDTO.getIsNecessary() || companyNecessaryFieldUpdateDTO.getIsEdit() == 1)) {
            companyNecessaryFieldUpdateDTO.setIsOpen(true);
        }
        //转DO
        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldUpdateDTO.to(CompanyNecessaryFieldDO.class);
        //根据主键更新，只更新非null值
        return updateByIdSelective(companyNecessaryFieldDO, tokenUser.getSiteId(), tokenUser.getUserId());
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int updateForApp(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser, String type) {
        if (StringUtils.isEmpty(type)) {
            //公司员工基本信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "basic", Boolean.TRUE);
            //公司员工基本额外信息
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, "basic", Boolean.TRUE);
            //公司员工家庭成员信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "empFamily", Boolean.TRUE);
            //公司员工联系人所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "contact", Boolean.TRUE);
            //公司员工联系人所需额外信息
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, "contact", Boolean.TRUE);
            //公司员工工作经历所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "empWork", Boolean.TRUE);
            //公司员工教育经历所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "empEducation", Boolean.TRUE);
            //公司员工紧急联系人所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "empContacts", Boolean.TRUE);
            //公司员工培训记录所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "empTrain", Boolean.TRUE);
            //司员工附件所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "annex", Boolean.TRUE);
            //司员工附件所需额外信息
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, "annex", Boolean.TRUE);
            //公司员工银行所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "bank", Boolean.TRUE);
            //公司员工员工档案资料所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "archive", Boolean.TRUE);
            //公司员工员工档案资料所需额外信息
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, "archive", Boolean.TRUE);
            //公司员工离职资料附件所需信息
            completeUpdate(companyFieldAndValueListVO, tokenUser, "leaveOffice", Boolean.TRUE);
            //公司员工离职资料附件所需额外信息
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, "leaveOffice", Boolean.TRUE);
            if (companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList().get(0).getEmpInfoVO() != null) {
                EmpInfoUpdateDTO empInfoUpdateDTO = new EmpInfoUpdateDTO();
                empInfoUpdateDTO.setId(companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList().get(0).getEmpInfoVO().getId());
                empInfoUpdateDTO.setIsImprove(true);
                empInfoService.update(empInfoUpdateDTO, tokenUser);
                EmpInfoVO empInfoVO = companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList().get(0).getEmpInfoVO();
                personalEventService.autoSave(empInfoVO, tokenUser, PersonalEventEnum.DETAILS_INFO.getDesc(),
                        PersonalEventEnum.DETAILS_INFO.getValue(), PersonalEventEnum.DETAILS_INFO.getDesc());

            }

            //对五个模块进行校验
            completeModule(companyFieldAndValueListVO, tokenUser, Boolean.TRUE);

        } else {
            completeUpdate(companyFieldAndValueListVO, tokenUser, type, Boolean.FALSE);
            completeAdditionalUpdate(companyFieldAndValueListVO, tokenUser, type, Boolean.FALSE);
        }
        return 1;
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int updateAppForModule(CompanyFieldAndValueUpdateVO companyFieldAndValueUpdateVO, TokenUser tokenUser) {
        String needCompleteThing = "";
        switch (companyFieldAndValueUpdateVO.getType()) {
            case "empContacts":
                int empContactsNum = 0;
                EmpContactsListVO empContactsListVO = new EmpContactsListVO();
                if (companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpContactsListVO() != null) {
                    empContactsListVO =
                            companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpContactsListVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String empFamilyString = "";
                        if (companyNecessaryFieldVO.getEmpContactsListVO() != null) {
                            empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpContactsListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        }
                        if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        if (companyNecessaryFieldVO.getEmpContactsListVO() != null) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpContactsListVO(), companyNecessaryFieldVO.getFieldCode());
                            if (obj != null) {
                                ClassKit.inject(empContactsListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                                empContactsNum++;
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    throw new ParamException(needCompleteThing + "字段需要填写");
                }
                if (empContactsNum == 0) {
                    break;
                }
                //判断修改or添加
                if (empContactsListVO.getId() == null) {
                    EmpContactsAddDTO empContactsAddDTO = empContactsListVO.to(EmpContactsAddDTO.class);
                    empContactsService.save(empContactsAddDTO, tokenUser);
                } else {
                    EmpContactsUpdateDTO empContactsUpdateDTO = empContactsListVO.to(EmpContactsUpdateDTO.class);
                    empContactsService.update(empContactsUpdateDTO, tokenUser);
                }
                break;
            case "empEducation":
                EmpEducationVO empEducationVO = new EmpEducationVO();
                int empEducationNum = 0;
                if (companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpEducationVO() != null) {
                    empEducationVO = companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpEducationVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String empFamilyString = "";
                        if (companyNecessaryFieldVO.getEmpEducationVO() != null) {
                            empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpEducationVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        }
                        if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        if (companyNecessaryFieldVO.getEmpEducationVO() != null) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpEducationVO(), companyNecessaryFieldVO.getFieldCode());
                            if (obj != null) {
                                ClassKit.inject(empEducationVO, companyNecessaryFieldVO.getFieldCode(), obj);
                                empEducationNum++;
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    throw new ParamException(needCompleteThing + "字段需要填写");
                }
                if (empEducationNum == 0) {
                    break;
                }
                if (empEducationVO.getStartTime() != null) {
                    if (empEducationVO.getEndTime() != null) {
                        if (empEducationVO.getStartTime().compareTo(empEducationVO.getEndTime()) == 1) {
                            throw new ParamException("开始时间不能大于结束时间");
                        }
                    }
                    if (empEducationVO.getStartTime().compareTo(new Date()) == 1) {
                        throw new ParamException("开始时间不能大于当前时间");
                    }
                }
                if (empEducationVO.getId() == null) {
                    EmpEducationAddDTO empEducationAddDTO = empEducationVO.to(EmpEducationAddDTO.class);
                    empEducationService.save(empEducationAddDTO, tokenUser);
                } else {
                    EmpEducationUpdateDTO empEducationUpdateDTO = empEducationVO.to(EmpEducationUpdateDTO.class);
                    empEducationService.update(empEducationUpdateDTO, tokenUser);
                }
                break;
            case "empFamily":
                int empFamilyNum = 0;
                EmpFamilyVO empFamilyVO = new EmpFamilyVO();
                if (companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpFamilyVO() != null) {
                    empFamilyVO = companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpFamilyVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String empFamilyString = "";
                        if (companyNecessaryFieldVO.getEmpFamilyVO() != null) {
                            empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpFamilyVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        }
                        if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        if (companyNecessaryFieldVO.getEmpFamilyVO() != null) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpFamilyVO(), companyNecessaryFieldVO.getFieldCode());
                            if (obj != null) {
                                ClassKit.inject(empFamilyVO, companyNecessaryFieldVO.getFieldCode(), obj);
                                empFamilyNum++;
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    throw new ParamException(needCompleteThing + "字段需要填写");
                }
                if (empFamilyNum == 0) {
                    break;
                }
                if (empFamilyVO.getId() == null) {
                    EmpFamilyAddDTO empFamilyAddDTO = empFamilyVO.to(EmpFamilyAddDTO.class);
                    empFamilyService.save(empFamilyAddDTO, tokenUser);
                } else {
                    EmpFamilyUpdateDTO empFamilyUpdateDTO = empFamilyVO.to(EmpFamilyUpdateDTO.class);
                    empFamilyService.update(empFamilyUpdateDTO, tokenUser);
                }
                break;
            case "empTrain":
                int empTrainNum = 0;
                EmpTrainListVO empTrainListVO = new EmpTrainListVO();
                if (companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpTrainListVO() != null) {
                    empTrainListVO = companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpTrainListVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String empFamilyString = "";
                        if (companyNecessaryFieldVO.getEmpTrainListVO() != null) {
                            empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpTrainListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        }
                        if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        if (companyNecessaryFieldVO.getEmpTrainListVO() != null) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpTrainListVO(), companyNecessaryFieldVO.getFieldCode());
                            if (obj != null) {
                                ClassKit.inject(empTrainListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                                empTrainNum++;
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    throw new ParamException(needCompleteThing + "字段需要填写");
                }
                if (empTrainNum == 0) {
                    break;
                }
                if (empTrainListVO.getStartTime() != null) {
                    if (empTrainListVO.getEndTime() != null) {
                        if (empTrainListVO.getStartTime().compareTo(empTrainListVO.getEndTime()) == 1) {
                            throw new ParamException("开始时间不能大于结束时间");
                        }
                    }
                    if (empTrainListVO.getStartTime().compareTo(new Date()) == 1) {
                        throw new ParamException("开始时间不能大于当前时间");
                    }
                }
                if (empTrainListVO.getId() == null) {
                    EmpTrainAddDTO empTrainAddDTO = empTrainListVO.to(EmpTrainAddDTO.class);
                    empTrainService.save(empTrainAddDTO, tokenUser);
                } else {
                    EmpTrainUpdateDTO empTrainUpdateDTO = empTrainListVO.to(EmpTrainUpdateDTO.class);
                    empTrainService.update(empTrainUpdateDTO, tokenUser);
                }
                break;
            case "empWork":
                int empWorkNum = 0;
                EmpWorkListVO empWorkListVO = new EmpWorkListVO();
                if (companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpWorkListVO() != null) {
                    empWorkListVO = companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList().get(0).getEmpWorkListVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueUpdateVO.getCompanyNecessaryFieldVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String empFamilyString = "";
                        if (companyNecessaryFieldVO.getEmpWorkListVO() != null) {
                            empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpWorkListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        }
                        if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        if (companyNecessaryFieldVO.getEmpWorkListVO() != null) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpWorkListVO(), companyNecessaryFieldVO.getFieldCode());
                            if (obj != null) {
                                ClassKit.inject(empWorkListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                                empWorkNum++;
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    throw new ParamException(needCompleteThing + "字段需要填写");
                }
                if (empWorkNum == 0) {
                    break;
                }
                if (empWorkListVO.getStartTime() != null) {
                    if (empWorkListVO.getEndTime() != null) {
                        if (empWorkListVO.getStartTime().compareTo(empWorkListVO.getEndTime()) == 1) {
                            throw new ParamException("开始时间不能大于结束时间");
                        }
                    }
                    if (empWorkListVO.getStartTime().compareTo(new Date()) == 1) {
                        throw new ParamException("开始时间不能大于当前时间");
                    }
                }
                if (empWorkListVO.getId() == null) {
                    EmpWorkAddDTO empWorkAddDTO = empWorkListVO.to(EmpWorkAddDTO.class);
                    empWorkService.save(empWorkAddDTO, tokenUser);
                } else {
                    EmpWorkUpdateDTO empWorkUpdateDTO = empWorkListVO.to(EmpWorkUpdateDTO.class);
                    empWorkService.update(empWorkUpdateDTO, tokenUser);
                }

                break;
            default:
                break;
        }
        return 1;
    }

    private String completeModule(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser, Boolean isAll) {
        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOList = companyFieldAndValueListVO.getCompanyEmpNecessaryVOList();
        String returnValue = "";
        for (CompanyEmpNecessaryVO companyEmpNecessaryVO : companyEmpNecessaryVOList) {
            if (companyEmpNecessaryVO.getIsNecessary()) {
                switch (companyEmpNecessaryVO.getModuleCode()) {
                    case "empWork":
                        if (companyFieldAndValueListVO.getCompanyEmpNecessaryWorkVOList().size() < 1) {
                            returnValue += "需要添加" + companyEmpNecessaryVO.getModuleName() + " ";
                            if (isAll) {
                                throw new ParamException(returnValue);
                            }
                        }
                        break;
                    case "empTrain":
                        if (companyFieldAndValueListVO.getCompanyEmpNecessaryTrainVOList().size() < 1) {
                            returnValue += "需要添加" + companyEmpNecessaryVO.getModuleName() + " ";
                            if (isAll) {
                                throw new ParamException(returnValue);
                            }
                        }
                        break;
                    case "empEducation":
                        if (companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList().size() < 1) {
                            returnValue += "需要添加" + companyEmpNecessaryVO.getModuleName() + " ";
                            if (isAll) {
                                throw new ParamException(returnValue);
                            }
                        }
                        break;
                    case "empFamily":
                        if (companyFieldAndValueListVO.getCompanyEmpNecessaryFamilyMembersVOList().size() < 1) {
                            returnValue += "需要添加" + companyEmpNecessaryVO.getModuleName() + " ";
                            if (isAll) {
                                throw new ParamException(returnValue);
                            }
                        }
                        break;
                    case "empContacts":
                        if (companyFieldAndValueListVO.getCompanyEmpNecessaryEmergencyContactVOList().size() < 1) {
                            returnValue += "需要添加" + companyEmpNecessaryVO.getModuleName() + " ";
                            if (isAll) {
                                throw new ParamException(returnValue);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
        }
        return returnValue;
    }

    /**
     * 基本信息的修改
     *
     * @param companyFieldAndValueListVO 基本信息
     * @param tokenUser                  登录人
     * @param type                       类型
     * @param isAll                      是否时全局的保存
     * @return 失败字段
     */
    private String completeUpdate(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser, String type, Boolean isAll) {
        String needCompleteThing = "";
        switch (type) {
            case "annex":
                EmpInfoVO empInfoVO = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoVO = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoVO, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }
                }
                if (empInfoVO.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoVO.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoVO.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }

                break;
            case "bank":
                EmpInfoVO empInfoBank = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoBank = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoBank, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }

                }
                if (empInfoBank.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoBank.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoBank.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }
                break;
            case "basic":
                EmpInfoVO empInfoBasic = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoBasic = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoBasic, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }

                }
                if (empInfoBasic.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoBasic.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoBasic.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }
                break;
            case "contact":
                EmpInfoVO empInfoContact = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoContact = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoContact, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }

                }
                if (empInfoContact.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoContact.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoContact.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }
                break;
            case "archive":
                EmpInfoVO empInfoArchive = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoArchive = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoArchive, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }
                }
                if (empInfoArchive.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoArchive.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoArchive.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }
                break;
            case "leaveOffice":
                EmpInfoVO empInfoLeaveOffice = new EmpInfoVO();
                if (companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO() != null) {
                    empInfoLeaveOffice = companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getEmpInfoVO();
                }

                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList()) {
                    //必填
                    if (companyNecessaryFieldVO.getIsNecessary()) {
                        //是否为空
                        String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                        if ("".equals(s) || "null".equals(s)) {
                            if ("".equals(needCompleteThing)) {
                                needCompleteThing = companyNecessaryFieldVO.getFieldName();
                            } else {
                                needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                            }
                        }
                    }
                    //添加进去
                    if (companyNecessaryFieldVO.getIsEdit() == 1) {
                        Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode());
                        ClassKit.inject(empInfoLeaveOffice, companyNecessaryFieldVO.getFieldCode(), obj);
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    if (isAll) {
                        throw new ParamException(
                                companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList().get(0).getModuleName() +
                                        "模块：" + needCompleteThing + "需要填写");
                    } else {
                        throw new ParamException(needCompleteThing + "字段需要填写");
                    }
                }
                if (empInfoLeaveOffice.getId() == null) {
                    EmpInfoAddDTO empInfoAddDTO = empInfoLeaveOffice.to(EmpInfoAddDTO.class);
                    empInfoService.save(empInfoAddDTO, tokenUser);
                } else {
                    EmpInfoUpdateDTO empInfoUpdateDTO = empInfoLeaveOffice.to(EmpInfoUpdateDTO.class);
                    empInfoService.update(empInfoUpdateDTO, tokenUser);
                }
                break;
            case "empContacts":
                for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                        companyFieldAndValueListVO.getCompanyEmpNecessaryEmergencyContactVOList()) {
                    EmpContactsListVO empContactsListVO = new EmpContactsListVO();
                    int empContactsListVONum = 0;
                    if (companyNecessaryFieldVOList.get(0).getEmpContactsListVO() != null) {
                        empContactsListVO = companyNecessaryFieldVOList.get(0).getEmpContactsListVO();
                    }
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpContactsListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                        //添加进去
                        if (companyNecessaryFieldVO.getIsEdit() == 1) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpContactsListVO(), companyNecessaryFieldVO.getFieldCode());
                            ClassKit.inject(empContactsListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                            empContactsListVONum++;
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        if (isAll) {
                            throw new ParamException(companyNecessaryFieldVOList.get(0).getModuleName() + "模块："
                                    + needCompleteThing + "需要填写");
                        } else {
                            throw new ParamException(needCompleteThing + "字段需要填写");
                        }

                    }
                    if (empContactsListVONum != 0) {
                        //判断修改or添加
                        if (empContactsListVO.getId() == null) {
                            EmpContactsAddDTO empContactsAddDTO = empContactsListVO.to(EmpContactsAddDTO.class);
                            empContactsService.save(empContactsAddDTO, tokenUser);
                        } else {
                            EmpContactsUpdateDTO empContactsUpdateDTO = empContactsListVO.to(EmpContactsUpdateDTO.class);
                            empContactsService.update(empContactsUpdateDTO, tokenUser);
                        }
                    }
                }
                break;
            case "empEducation":
                for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                        companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList()) {
                    int empEducationVONum = 0;
                    EmpEducationVO empEducationVO = new EmpEducationVO();
                    if (companyNecessaryFieldVOList.get(0).getEmpEducationVO() != null) {
                        empEducationVO = companyNecessaryFieldVOList.get(0).getEmpEducationVO();
                    }
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpEducationVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                        //添加进去
                        if (companyNecessaryFieldVO.getIsEdit() == 1) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpEducationVO(), companyNecessaryFieldVO.getFieldCode());
                            ClassKit.inject(empEducationVO, companyNecessaryFieldVO.getFieldCode(), obj);
                            empEducationVONum++;
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        if (isAll) {
                            throw new ParamException(companyNecessaryFieldVOList.get(0).getModuleName() + "模块："
                                    + needCompleteThing + "需要填写");
                        } else {
                            throw new ParamException(needCompleteThing + "字段需要填写");
                        }
                    }
                    if (empEducationVONum != 0) {
                        if (empEducationVO.getId() == null) {
                            EmpEducationAddDTO empEducationAddDTO = empEducationVO.to(EmpEducationAddDTO.class);
                            empEducationService.save(empEducationAddDTO, tokenUser);
                        } else {
                            EmpEducationUpdateDTO empEducationUpdateDTO = empEducationVO.to(EmpEducationUpdateDTO.class);
                            empEducationService.update(empEducationUpdateDTO, tokenUser);
                        }
                    }
                }
                break;
            case "empFamily":
                for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                        companyFieldAndValueListVO.getCompanyEmpNecessaryFamilyMembersVOList()) {
                    int empFamilyVONum = 0;
                    EmpFamilyVO empFamilyVO = new EmpFamilyVO();
                    if (companyNecessaryFieldVOList.get(0).getEmpFamilyVO() != null) {
                        empFamilyVO = companyNecessaryFieldVOList.get(0).getEmpFamilyVO();
                    }
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpFamilyVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                        //添加进去
                        if (companyNecessaryFieldVO.getIsEdit() == 1) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpFamilyVO(), companyNecessaryFieldVO.getFieldCode());
                            ClassKit.inject(empFamilyVO, companyNecessaryFieldVO.getFieldCode(), obj);
                            empFamilyVONum++;
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        if (isAll) {
                            throw new ParamException(companyNecessaryFieldVOList.get(0).getModuleName() + "模块："
                                    + needCompleteThing + "需要填写");
                        } else {
                            throw new ParamException(needCompleteThing + "字段需要填写");
                        }

                    }
                    if (empFamilyVONum != 0) {
                        if (empFamilyVO.getId() == null) {
                            EmpFamilyAddDTO empFamilyAddDTO = empFamilyVO.to(EmpFamilyAddDTO.class);
                            empFamilyService.save(empFamilyAddDTO, tokenUser);
                        } else {
                            EmpFamilyUpdateDTO empFamilyUpdateDTO = empFamilyVO.to(EmpFamilyUpdateDTO.class);
                            empFamilyService.update(empFamilyUpdateDTO, tokenUser);
                        }
                    }
                }
                break;
            case "empTrain":
                for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                        companyFieldAndValueListVO.getCompanyEmpNecessaryTrainVOList()) {
                    EmpTrainListVO empTrainListVO = new EmpTrainListVO();
                    int empTrainListVONum = 0;
                    if (companyNecessaryFieldVOList.get(0).getEmpTrainListVO() != null) {
                        empTrainListVO = companyNecessaryFieldVOList.get(0).getEmpTrainListVO();
                    }
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpTrainListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                        //添加进去
                        if (companyNecessaryFieldVO.getIsEdit() == 1) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpTrainListVO(), companyNecessaryFieldVO.getFieldCode());
                            ClassKit.inject(empTrainListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                            empTrainListVONum++;
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        if (isAll) {
                            throw new ParamException(companyNecessaryFieldVOList.get(0).getModuleName() + "模块："
                                    + needCompleteThing + "需要填写");
                        } else {
                            throw new ParamException(needCompleteThing + "字段需要填写");
                        }
                    }
                    if (empTrainListVONum != 0) {
                        if (empTrainListVO.getId() == null) {
                            EmpTrainAddDTO empTrainAddDTO = empTrainListVO.to(EmpTrainAddDTO.class);
                            empTrainService.save(empTrainAddDTO, tokenUser);
                        } else {
                            EmpTrainUpdateDTO empTrainUpdateDTO = empTrainListVO.to(EmpTrainUpdateDTO.class);
                            empTrainService.update(empTrainUpdateDTO, tokenUser);
                        }
                    }
                }
                break;
            case "empWork":
                for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                        companyFieldAndValueListVO.getCompanyEmpNecessaryWorkVOList()) {
                    EmpWorkListVO empWorkListVO = new EmpWorkListVO();
                    int empWorkListVONum = 0;
                    if (companyNecessaryFieldVOList.get(0).getEmpWorkListVO() != null) {
                        empWorkListVO = companyNecessaryFieldVOList.get(0).getEmpWorkListVO();
                    }
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpWorkListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "," + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                        //添加进去
                        if (companyNecessaryFieldVO.getIsEdit() == 1) {
                            Object obj = ClassKit.getValue(companyNecessaryFieldVO.getEmpWorkListVO(), companyNecessaryFieldVO.getFieldCode());
                            ClassKit.inject(empWorkListVO, companyNecessaryFieldVO.getFieldCode(), obj);
                            empWorkListVONum++;
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        if (isAll) {
                            throw new ParamException(companyNecessaryFieldVOList.get(0).getModuleName() + "模块："
                                    + needCompleteThing + "需要填写");
                        } else {
                            throw new ParamException(needCompleteThing + "字段需要填写");
                        }

                    }
                    if (empWorkListVONum != 0) {
                        if (empWorkListVO.getId() == null) {
                            EmpWorkAddDTO empWorkAddDTO = empWorkListVO.to(EmpWorkAddDTO.class);
                            empWorkService.save(empWorkAddDTO, tokenUser);
                        } else {
                            EmpWorkUpdateDTO empWorkUpdateDTO = empWorkListVO.to(EmpWorkUpdateDTO.class);
                            empWorkService.update(empWorkUpdateDTO, tokenUser);
                        }
                    }
                }
                break;
            default:
                break;
        }
        return needCompleteThing;
    }


    /**
     * 额外字段信息的修改
     *
     * @param companyFieldAndValueListVO 额外字段信息
     * @param tokenUser                  登录人
     * @param type                       类型
     * @param isAll                      是否时全部查看
     * @return 失败字段
     */
    private String completeAdditionalUpdate(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser, String type, Boolean isAll) {
        String needCompleteThing = "";
        switch (type) {
            case "annex":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsAttachmentVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsAttachmentVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if (isAll) {
                                    throw new ParamException("员工额外资料模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                }
                            }
                        }
                        if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() != null) {
                            if (companyAdditionalFieldsListVO.getFieldType() == 2 &&
                                    companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent() != null &&
                                    companyAdditionalFieldsListVO.getTextLength() <
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent().length()) {
                                if (isAll) {
                                    throw new ParamException("员工额外资料模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                }
                            }

                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getId() == null) {
                                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO =
                                        companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsAddDTO.class);
                                empAdditionalFieldsService.save(empAdditionalFieldsAddDTO, tokenUser);
                            } else {
                                if (companyAdditionalFieldsListVO.getIsEdit() == 1) {
                                    EmpAdditionalFieldsUpdateDTO empAdditionalFieldsUpdateDTO =
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsUpdateDTO.class);
                                    empAdditionalFieldsService.update(empAdditionalFieldsUpdateDTO, tokenUser);
                                }
                            }
                        }

                    }
                }
                break;
            case "basic":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsBasicVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsBasicVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if (isAll) {
                                    throw new ParamException("员工基本资料模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                }

                            }
                        }
                        if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() != null) {
                            if (companyAdditionalFieldsListVO.getFieldType() == 2 &&
                                    companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent() != null &&
                                    companyAdditionalFieldsListVO.getTextLength() <
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent().length()) {
                                if (isAll) {
                                    throw new ParamException("员工基本资料模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                }

                            }

                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getId() == null) {
                                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO =
                                        companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsAddDTO.class);
                                empAdditionalFieldsService.save(empAdditionalFieldsAddDTO, tokenUser);
                            } else {
                                if (companyAdditionalFieldsListVO.getIsEdit() == 1) {
                                    EmpAdditionalFieldsUpdateDTO empAdditionalFieldsUpdateDTO =
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsUpdateDTO.class);
                                    empAdditionalFieldsService.update(empAdditionalFieldsUpdateDTO, tokenUser);
                                }
                            }

                        }
                    }
                }
                break;
            case "contact":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsContactVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsContactVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if (isAll) {
                                    throw new ParamException("员工联系人模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                }
                            }
                        }
                        if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() != null) {
                            if (companyAdditionalFieldsListVO.getFieldType() == 2 &&
                                    companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent() != null &&
                                    companyAdditionalFieldsListVO.getTextLength() <
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent().length()) {
                                if (isAll) {
                                    throw new ParamException("员工联系人模块" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                }

                            }

                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getId() == null) {
                                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO =
                                        companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsAddDTO.class);
                                empAdditionalFieldsService.save(empAdditionalFieldsAddDTO, tokenUser);
                            } else {
                                if (companyAdditionalFieldsListVO.getIsEdit() == 1) {
                                    EmpAdditionalFieldsUpdateDTO empAdditionalFieldsUpdateDTO =
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsUpdateDTO.class);
                                    empAdditionalFieldsService.update(empAdditionalFieldsUpdateDTO, tokenUser);
                                }
                            }

                        }
                    }
                }
                break;
            case "archive":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsArchiveVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsArchiveVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if (isAll) {
                                    throw new ParamException("员工档案资料所需信息" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                }

                            }
                        }
                        if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() != null) {
                            if (companyAdditionalFieldsListVO.getFieldType() == 2 &&
                                    companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent() != null &&
                                    companyAdditionalFieldsListVO.getTextLength() <
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent().length()) {
                                if (isAll) {
                                    throw new ParamException("员工档案资料所需信息" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                }

                            }
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getId() == null) {
                                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO =
                                        companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsAddDTO.class);
                                empAdditionalFieldsService.save(empAdditionalFieldsAddDTO, tokenUser);
                            } else {
                                if (companyAdditionalFieldsListVO.getIsEdit() == 1) {
                                    EmpAdditionalFieldsUpdateDTO empAdditionalFieldsUpdateDTO =
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsUpdateDTO.class);
                                    empAdditionalFieldsService.update(empAdditionalFieldsUpdateDTO, tokenUser);
                                }
                            }
                        }
                    }
                }
                break;
            case "leaveOffice":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsLeaveOfficeVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsLeaveOfficeVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if (isAll) {
                                    throw new ParamException("员工离职资料附件所需信息" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段不能为空");
                                }

                            }
                        }
                        if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() != null) {
                            if (companyAdditionalFieldsListVO.getFieldType() == 2 &&
                                    companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent() != null &&
                                    companyAdditionalFieldsListVO.getTextLength() <
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent().length()) {
                                if (isAll) {
                                    throw new ParamException("员工离职资料附件所需信息" + companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                } else {
                                    throw new ParamException(companyAdditionalFieldsListVO.getFieldName()
                                            + "字段过长，不能超过" + companyAdditionalFieldsListVO.getTextLength() + "字");
                                }

                            }
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getId() == null) {
                                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO =
                                        companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsAddDTO.class);
                                empAdditionalFieldsService.save(empAdditionalFieldsAddDTO, tokenUser);
                            } else {
                                if (companyAdditionalFieldsListVO.getIsEdit() == 1) {
                                    EmpAdditionalFieldsUpdateDTO empAdditionalFieldsUpdateDTO =
                                            companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().to(EmpAdditionalFieldsUpdateDTO.class);
                                    empAdditionalFieldsService.update(empAdditionalFieldsUpdateDTO, tokenUser);
                                }
                            }
                        }
                    }
                }
                break;
            default:
                break;
        }
        return needCompleteThing;
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int deleteByIds(TokenUser tokenUser, String... companyNecessaryFieldIds) {
        return logicalDeleteByIds(tokenUser.getSiteId(), tokenUser.getUserId(), (Object[]) companyNecessaryFieldIds);
    }


    @Override
    public CompanyNecessaryFieldVO selectById(String companyNecessaryFieldId, String siteId) {
        CompanyNecessaryFieldDO companyNecessaryFieldDO = selectDOById(companyNecessaryFieldId, siteId);
        if (companyNecessaryFieldDO == null) {
            return null;
        }
        return companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
    }

    @Override
    public List<CompanyNecessaryFieldListVO> select(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        if (selectIsEmptyByCompanyId(companyNecessaryFieldQuery.getCompanyId())) {
            //空的时候创建一套
            necessaryInitializationByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
            //然后重新查一下
            return select(companyNecessaryFieldQuery, tokenUser);
        }
        return companyNecessaryFieldDOList.stream()
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldListVO.class))
                .collect(Collectors.toList());
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectByModuleAndFiledName(String moduleCode, String filedName, String companyId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("fieldName", filedName)
                .andEqualTo("companyId", companyId);
        if (moduleCode != null) {
            example.and().andEqualTo("moduleCode", moduleCode);
        }
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectByFiledNames(List<String> filedNames) {
        if (CollectionUtils.isEmpty(filedNames)) {
            return new ArrayList<>();
        }
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andIn("fieldName", filedNames);
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public CompanyFieldForPcListVO listAllForPc(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        CompanyFieldForPcListVO companyFieldForPcListVO = new CompanyFieldForPcListVO();
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        if (selectIsEmptyByCompanyId(companyNecessaryFieldQuery.getCompanyId())) {
            //空的时候创建一套
            necessaryInitializationByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
            //然后重新查一下
            return listAllForPc(companyNecessaryFieldQuery, tokenUser);
        }
        List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
            CompanyNecessaryFieldVO companyNecessaryFieldVO = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
            companyNecessaryFieldVOList.add(companyNecessaryFieldVO);
        }
        CompanyAdditionalFieldsQuery companyAdditionalFieldsQuery = new CompanyAdditionalFieldsQuery();
        if (companyNecessaryFieldQuery.getModuleCode() != null) {
            companyAdditionalFieldsQuery.setModuleCode(companyNecessaryFieldQuery.getModuleCode());
        }
        if (companyNecessaryFieldQuery.getCompanyId() != null) {
            companyAdditionalFieldsQuery.setCompanyId(companyNecessaryFieldQuery.getCompanyId());
        }
        if (companyNecessaryFieldQuery.getIsNecessary() != null) {
            companyAdditionalFieldsQuery.setIsNecessary(companyNecessaryFieldQuery.getIsNecessary());
        }
        if (companyNecessaryFieldQuery.getIsOpen() != null) {
            companyAdditionalFieldsQuery.setIsOpen(companyNecessaryFieldQuery.getIsOpen());
        }
        Map<String, List<CompanyAdditionalFieldsListVO>> companyAdditionalFieldsListMap = new HashMap<>();
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.select(companyAdditionalFieldsQuery, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(companyAdditionalFieldsListVOList)) {
            companyAdditionalFieldsListMap =
                    companyAdditionalFieldsListVOList.stream().collect(
                            Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        }
        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOList =
                companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        // 处理顺序：紧急联系人-教育经历-家庭成员-培训经历-工作经历
        List<CompanyEmpNecessaryVO> empNecessaryVOS = new ArrayList<>();
        for (CompanyEmpNecessaryVO companyEmpNecessaryVO : companyEmpNecessaryVOList) {
            switch (companyEmpNecessaryVO.getModuleName()) {
                case "紧急联系人":
                    companyEmpNecessaryVO.setSort(1);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "教育经历":
                    companyEmpNecessaryVO.setSort(2);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "家庭成员":
                    companyEmpNecessaryVO.setSort(3);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "培训经历":
                    companyEmpNecessaryVO.setSort(4);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "工作经历":
                    companyEmpNecessaryVO.setSort(5);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
            }
        }
        empNecessaryVOS.sort(Comparator.comparingInt(CompanyEmpNecessaryVO::getSort));
        companyFieldForPcListVO.setCompanyEmpNecessaryVOList(empNecessaryVOS);
        Map<String, List<CompanyNecessaryFieldVO>> companyNecessaryFieldMap = companyNecessaryFieldVOList.stream()
                .collect(Collectors.groupingBy(CompanyNecessaryFieldVO::getModuleCode));
        complete(companyFieldForPcListVO, companyAdditionalFieldsListMap, companyNecessaryFieldMap);
        return companyFieldForPcListVO;
    }


    /**
     * 查询公司下必填字段是否存在
     *
     * @param companyId 公司Id
     * @return 公司下必填字段数量
     */
    private boolean selectIsEmptyByCompanyId(String companyId) {
        String lockKey = "listAllForPc" + companyId;
        RLock lock = redissonClient.getLock(lockKey);
        boolean hasLock;
        try {
            // 加锁，等待0秒，上锁以后300秒自动解锁
            hasLock = lock.tryLock(0, 300, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        if (!hasLock) {
            log.warn("pc端查询公司员工必填字段信息重复点击");
            throw new ParamException("请勿重复提交");
        }
        boolean b;
        try {
            Example example = new Example(CompanyEmpNecessaryDO.class);
            example.and()
                    .andEqualTo("valid", true)
                    .andEqualTo("companyId", companyId);
            b = companyNecessaryFieldDAO.selectCountByExample(example) < 1;
        } finally {
            //释放锁
            if (lock.isLocked() && lock.isHeldByCurrentThread()) {
                lock.unlock();
            }
        }
        return b;
    }

    @Override
    public boolean filterField(String fieldName, String siteId) {
        Map<String, SiteDO> siteMap = adminProviderService.selectSiteMap();
        SiteDO siteDO = siteMap.get(siteId);
        if (siteDO == null) {
            log.error("所在租户不存在, 租户Id：{}", siteId);
            throw new ParamException("所在租户不存在");
        }
        // 非甲方端租户不需要过滤
        if (siteDO.getSiteType() != 3 && siteDO.getSiteType() != 4) {
            return Boolean.TRUE;
        }
        ArrayList<String> notList = new ArrayList<>(Arrays.asList("工作性质"));
        return !notList.contains(fieldName);
    }

    @Override
    public List<CompanyFieldInfoVO> listForPc(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        SiteVO site = adminProviderService.selectSiteById(tokenUser.getSiteId(), tokenUser);
        List<CompanyFieldInfoVO> companyFieldInfoList = new ArrayList<>();
        //查询moduleCode是否必填
        List<CompanyEmpNecessaryVO> moduleCodeList = companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        Map<String, CompanyEmpNecessaryVO> moduleNecessaryMap = moduleCodeList.stream()
                .collect(Collectors.toMap(CompanyEmpNecessaryVO::getModuleCode, Function.identity()));
        //查询所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = this.selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());

        if (CollectionUtils.isEmpty(companyNecessaryFieldDOList)) {
            // 公司下个人信息设置查询不到 初始化
            Integer integer = necessaryInitializationByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
            ParamException.isTrue(integer > 0, "初始化公司个人信息设置失败，请联系管理员");
            ParamException.isTrue(initializationNum < 3, "多次初始化公司个人信息设置，请检查查询条件");
            initializationNum++;
            return listForPc(companyNecessaryFieldQuery, tokenUser);
        }
        initializationNum = 0;
        //所有字段根据moduleCode分组
        Map<String, List<CompanyNecessaryFieldDO>> moduleFieldListMap = companyNecessaryFieldDOList.stream()
                //只查指定分类的moduleCode
                .filter(companyNecessaryFieldDO -> EmpFieldModuleCodeKit.isModuleTypeInTypeList(companyNecessaryFieldQuery.getType(), companyNecessaryFieldDO.getModuleCode()))
                .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getModuleCode));
        //查询所有自定义字段
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser.getSiteId());
        //所有自定义字段根据moduleCode分组
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        //构造返回对象
        moduleFieldListMap.forEach((moduleCode, fieldList) -> {
            CompanyFieldInfoVO companyFieldInfoVO = new CompanyFieldInfoVO();
            CompanyEmpNecessaryVO companyEmpNecessaryVO = moduleNecessaryMap.get(moduleCode);
            if (companyEmpNecessaryVO != null) {
                companyFieldInfoVO.setId(companyEmpNecessaryVO.getId());
                companyFieldInfoVO.setNecessary(companyEmpNecessaryVO.getIsNecessary());
            }
            companyFieldInfoVO.setModuleCode(moduleCode);
            companyFieldInfoVO.setModuleName(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode));
            companyFieldInfoVO.setSupportAdditional(EmpFieldModuleCodeKit.getModuleCodeSupportAdditional(moduleCode));
            companyFieldInfoVO.setSupportNecessaryCheck(EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode));
            List<CompanyNecessaryFieldVO> necessaryFieldList;
            // 甲方端不显示工作性质
            if (JIA_FANG_QY.equals(site.getSiteType()) || JIA_FANG_SY.equals(site.getSiteType())) {
                necessaryFieldList = fieldList.stream()
                        .map(field -> field.to(CompanyNecessaryFieldVO.class))
                        .filter(field -> !"工作性质".equals(field.getFieldName()))
                        .collect(Collectors.toList());
            } else {
                necessaryFieldList = fieldList.stream()
                        .map(field -> field.to(CompanyNecessaryFieldVO.class)).collect(Collectors.toList());
            }
            companyFieldInfoVO.setFieldList(necessaryFieldList);
            List<CompanyAdditionalFieldsListVO> additionalFieldList = additionalFieldMap.get(moduleCode);
            companyFieldInfoVO.setAdditionalFieldList(additionalFieldList == null ? new ArrayList<>() : additionalFieldList);
            if (!"家庭成员".equals(companyFieldInfoVO.getModuleName())
                    && !"紧急联系人".equals(companyFieldInfoVO.getModuleName())
                    && !"教育经历".equals(companyFieldInfoVO.getModuleName())
                    && !"工作经历".equals(companyFieldInfoVO.getModuleName())
                    && !"培训经历".equals(companyFieldInfoVO.getModuleName())
                    && !CollectionUtils.isEmpty(necessaryFieldList)) {
                companyFieldInfoVO.setNecessary(necessaryFieldList.parallelStream().anyMatch(CompanyNecessaryFieldVO::getIsNecessary));
            }
            companyFieldInfoList.add(companyFieldInfoVO);
        });
        return companyFieldInfoList.stream()
                .sorted(EmpFieldModuleCodeKit.getModuleCodeComparator())
                .collect(Collectors.toList());
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public List<CompanyFieldInfoVO> listForPc2(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        String companyId = companyNecessaryFieldQuery.getCompanyId();
        String moduleCode = companyNecessaryFieldQuery.getModuleCode();
        String fieldName = companyNecessaryFieldQuery.getFieldName();
        ParamException.notNull(companyId, "用工单位Id不能为空");
        ParamException.notNull(moduleCode, "模板类型不能为空");
        List<CompanyFieldInfoVO> companyFieldInfoList = new ArrayList<>();
        //查询moduleCode是否必填
        List<CompanyEmpNecessaryVO> moduleCodeList = companyEmpNecessaryService
                .selectByCompanyId(companyId, tokenUser);
        Map<String, CompanyEmpNecessaryVO> moduleNecessaryMap = moduleCodeList.stream()
                .collect(Collectors.toMap(CompanyEmpNecessaryVO::getModuleCode, Function.identity()));
        //查询所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList;
        // 预登记字段与花名册不一致 导致预登记可选查询hr_custom_template_field 入职、待入职可选查询花名册hr_company_necessary_field
        // hr_custom_template_field的moduleCode分为预登记、待入职、入职
        // hr_company_necessary_field的moduleCode分为基本信息、联系信息....（小模块）
        // 为了统一结果 将预登记查询结果放入基本信息模块中，非预登记查询条件模块code置空
        if ("checkIn".equals(moduleCode)) {
            List<CustomTemplateFieldDO> customTemplateFieldDOList = customTemplateFieldService
                    .selectByDefaultModuleCode("checkIn", fieldName, tokenUser);
            companyNecessaryFieldDOList = customTemplateFieldDOList.parallelStream().map(customTemplateFieldDO -> {
                CompanyNecessaryFieldDO companyNecessaryFieldDO = customTemplateFieldDO.to(CompanyNecessaryFieldDO.class);
                companyNecessaryFieldDO.setModuleCode("basic");
                return companyNecessaryFieldDO;
            }).sorted(Comparator.comparing(CompanyNecessaryFieldDO::getSort)).collect(Collectors.toList());
        } else {
            companyNecessaryFieldQuery.setModuleCode(null);
            companyNecessaryFieldDOList = this.selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        }

        // 若按名称查询字段 没查到后初始化信息
        if (CollectionUtils.isEmpty(companyNecessaryFieldDOList) && StringUtils.isEmpty(fieldName)) {
            // 公司下个人信息设置查询不到 初始化
            Integer integer = necessaryInitializationByCompanyId(companyId, tokenUser);
            ParamException.isTrue(integer > 0, "初始化公司个人信息设置失败，请联系管理员");
            ParamException.isTrue(initializationNum < 3, "多次初始化公司个人信息设置，请检查查询条件");
            initializationNum++;
            companyNecessaryFieldQuery.setModuleCode(moduleCode);
            return listForPc2(companyNecessaryFieldQuery, tokenUser);
        }
        initializationNum = 0;
        //所有字段根据moduleCode分组
        Map<String, List<CompanyNecessaryFieldDO>> moduleFieldListMap = companyNecessaryFieldDOList.stream()
                //只查指定分类的moduleCode
                .filter(companyNecessaryFieldDO -> EmpFieldModuleCodeKit
                        .isModuleTypeInTypeList(companyNecessaryFieldQuery.getType(), companyNecessaryFieldDO.getModuleCode()))
                .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getModuleCode));
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList;
        if ("checkIn".equals(moduleCode)) {
            companyAdditionalFieldsListVOList = companyAdditionalFieldsService.
                    listByCompanyId(moduleCode, companyId, HrConstants.TEMPLATE_ID_LIST, tokenUser);
            // 自定义字段 按名称模糊过滤
            if (!StringUtils.isEmpty(fieldName)) {
                companyAdditionalFieldsListVOList = companyAdditionalFieldsListVOList.parallelStream()
                        .filter(companyAdditionalFieldsListVO
                                -> companyAdditionalFieldsListVO.getFieldName().contains(fieldName)).collect(Collectors.toList());
            }
        } else {
            //查询所有自定义字段
            companyAdditionalFieldsListVOList =
                    companyAdditionalFieldsService.selectByCompanyId2(companyNecessaryFieldQuery.getCompanyId()
                            , companyNecessaryFieldQuery.getFieldName(), tokenUser.getSiteId());
        }
        //所有自定义字段根据moduleCode分组
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        // 统计不重复的模块
        Set<String> moduleCodes = companyNecessaryFieldDOList.parallelStream()
                .map(CompanyNecessaryFieldDO::getModuleCode).collect(Collectors.toSet());
        List<String> additionalModuleCodes = companyAdditionalFieldsListVOList.parallelStream()
                .map(CompanyAdditionalFieldsListVO::getModuleCode).distinct().collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(additionalModuleCodes)) {
            moduleCodes.addAll(additionalModuleCodes);
        }
        //构造返回对象
        for (String oneModuleCode : moduleCodes) {
            CompanyFieldInfoVO companyFieldInfoVO = new CompanyFieldInfoVO();
            CompanyEmpNecessaryVO companyEmpNecessaryVO = moduleNecessaryMap.get(oneModuleCode);
            if (companyEmpNecessaryVO != null) {
                companyFieldInfoVO.setId(companyEmpNecessaryVO.getId());
                companyFieldInfoVO.setNecessary(companyEmpNecessaryVO.getIsNecessary());
            }
            companyFieldInfoVO.setModuleCode(oneModuleCode);
            companyFieldInfoVO.setModuleName(EmpFieldModuleCodeKit.getModuleCodeZhName(oneModuleCode));
            companyFieldInfoVO.setSupportAdditional(EmpFieldModuleCodeKit.getModuleCodeSupportAdditional(oneModuleCode));
            companyFieldInfoVO.setSupportNecessaryCheck(EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(oneModuleCode));
            // 放入基础字段
            List<CompanyNecessaryFieldVO> necessaryFieldList = new ArrayList<>();
            List<CompanyNecessaryFieldDO> fieldList = moduleFieldListMap.get(oneModuleCode);
            if (!CollectionUtils.isEmpty(fieldList)) {
                necessaryFieldList = fieldList.stream().map(field -> {
                    CompanyNecessaryFieldVO necessaryFieldVO = field.to(CompanyNecessaryFieldVO.class);
                    if ("empFamily".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("name".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("familyName");
                        } else if ("relation".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("familyRelation");
                        } else if ("phone".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("familyPhone");
                        } else if ("workUnit".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("familyWorkUnit");
                        }
                    } else if ("empContacts".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("name".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("contactsName");
                        } else if ("relation".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("contactsRelation");
                        } else if ("phone".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("contactsPhone");
                        } else if ("address".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("contactsAddress");
                        }
                    } else if ("empEducation".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("endTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("eduEndTime");
                        } else if ("startTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("eduStartTime");
                        }
                    } else if ("empTrain".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("endTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("trainEndTime");
                        } else if ("startTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("trainStartTime");
                        }
                    } else if ("empWork".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("endTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("workEndTime");
                        } else if ("startTime".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("workStartTime");
                        } else if ("remark".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("workRemark");
                        }
                    } else if ("rewardsPunishments".equals(companyFieldInfoVO.getModuleCode())) {
                        if ("remark".equals(field.getFieldCode())) {
                            necessaryFieldVO.setFieldCode("rewardsRemark");
                        }
                    }
                    // 不显示的字段
                    List<String> hideList = new ArrayList<>(Arrays.asList("司龄", "录入人", "录入方式", "起缴时间"
                            , "参保城市", "社保账号", "医保账号", "公积金账号"));
                    if (hideList.contains(field.getFieldName())) {
                        return null;
                    }
                    // 不可编辑的字段
                    List<String> notListField = new ArrayList<>(Arrays.asList("转正日期", "试用期"));
                    if (notListField.contains(field.getFieldName())) {
                        necessaryFieldVO.setIsDisabled(Boolean.TRUE);
                    }
                    return necessaryFieldVO;
                }).filter(Objects::nonNull).filter(companyNecessaryFieldVO -> filterField(
                        companyNecessaryFieldVO.getFieldName(), tokenUser.getSiteId())).collect(Collectors.toList());
            }
            companyFieldInfoVO.setFieldList(necessaryFieldList);
            // 放入自定义字段
            List<CompanyAdditionalFieldsListVO> additionalFieldList = additionalFieldMap.get(oneModuleCode);
            companyFieldInfoVO.setAdditionalFieldList(additionalFieldList == null ? new ArrayList<>() : additionalFieldList);
            // 以下模块只要有必填 整个模块就是必填
            if (!"家庭成员".equals(companyFieldInfoVO.getModuleName())
                    && !"紧急联系人".equals(companyFieldInfoVO.getModuleName())
                    && !"教育经历".equals(companyFieldInfoVO.getModuleName())
                    && !"工作经历".equals(companyFieldInfoVO.getModuleName())
                    && !"培训经历".equals(companyFieldInfoVO.getModuleName())
                    && !CollectionUtils.isEmpty(necessaryFieldList)) {
                companyFieldInfoVO.setNecessary(necessaryFieldList.parallelStream()
                        .anyMatch(CompanyNecessaryFieldVO::getIsNecessary));
            }
            if (companyFieldInfoVO.getId() != null) {
                companyFieldInfoList.add(companyFieldInfoVO);
            }
        }
        return companyFieldInfoList.stream()
                .sorted(EmpFieldModuleCodeKit.getModuleCodeComparator())
                .collect(Collectors.toList());
    }

    @Override
    public List<CompanyNecessaryModuleCodeVO> listCompanyModuleCodes(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        List<CompanyNecessaryModuleCodeVO> companyNecessaryModuleCodeList = new ArrayList<>();
        //查询moduleCode是否必填
        List<CompanyEmpNecessaryVO> moduleCodeTempList = companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        Map<String, CompanyEmpNecessaryVO> moduleNecessaryMap = moduleCodeTempList.stream()
                .collect(Collectors.toMap(CompanyEmpNecessaryVO::getModuleCode, Function.identity()));
        //模块下的所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldList = this.selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        //所有字段根据moduleCode分组
        Map<String, List<CompanyNecessaryFieldVO>> moduleFieldListMap = companyNecessaryFieldList.stream()
                //只查指定分类的moduleCode
                .filter(companyNecessaryFieldDO -> EmpFieldModuleCodeKit.isModuleTypeInTypeList(companyNecessaryFieldQuery.getType(), companyNecessaryFieldDO.getModuleCode()))
                .filter(CompanyNecessaryFieldDO::getIsOpen)
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class))
                .collect(Collectors.groupingBy(CompanyNecessaryFieldVO::getModuleCode));
        //查询所有自定义字段
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser.getSiteId());
        //所有自定义字段根据moduleCode分组
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        List<String> moduleCodeList = EmpFieldModuleCodeKit.getAllModuleCodeList();
        moduleCodeList.forEach(moduleCode -> {
            // 过滤moduleCode
            if (!StringUtils.isEmpty(companyNecessaryFieldQuery.getModuleCode()) && !companyNecessaryFieldQuery.getModuleCode().equals(moduleCode)) {
               return;
            }
            CompanyNecessaryModuleCodeVO companyNecessaryModuleCodeVO = new CompanyNecessaryModuleCodeVO();
            companyNecessaryModuleCodeVO.setModuleCode(moduleCode);
            companyNecessaryModuleCodeVO.setModuleName(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode));
            companyNecessaryModuleCodeVO.setNecessary(EmpFieldModuleCodeKit.getModuleCodeNecessary(moduleCode));
            //必填还由员工设置确定
            CompanyEmpNecessaryVO companyEmpNecessaryVO = moduleNecessaryMap.get(moduleCode);
            if (companyEmpNecessaryVO != null) {
                companyNecessaryModuleCodeVO.setNecessary(companyEmpNecessaryVO.getIsNecessary());
            }
            //填写信息为多条
            companyNecessaryModuleCodeVO.setMultiple(EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode));
            //组装字段
            List<CompanyNecessaryFieldVO> fieldList = moduleFieldListMap.get(moduleCode);
            if (CollectionUtils.isEmpty(fieldList)) {
                fieldList = new ArrayList<>();
            }
            // 字段是否禁用
            List<String> notListField = new ArrayList<>(Arrays.asList("起缴时间", "参保城市", "社保账号", "医保账号", "公积金账号"));
            fieldList.parallelStream().forEach(companyNecessaryFieldVO -> {
                companyNecessaryFieldVO.setIsDisabled(notListField.contains(companyNecessaryFieldVO.getFieldName()));
            });
            EmpFieldModuleCodeKit.setFieldGroupName(fieldList);
            //设置字段的下拉选项数组
            EmpFieldModuleCodeKit.setFieldDropDownArray(companyNecessaryFieldQuery.getCompanyId(), fieldList, moduleCode, tokenUser.getSiteId());
            setPostType(fieldList, tokenUser);
            String moduleName = companyNecessaryModuleCodeVO.getModuleName();
            switch (moduleName) {
                case "员工状态":
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                        if ("转正日期".equals(companyNecessaryFieldVO.getFieldName())
                                || "司龄".equals(companyNecessaryFieldVO.getFieldName())) {
                            companyNecessaryFieldVO.setIsDisabled(Boolean.TRUE);
                        }
                    }
                    break;
                case "在职信息":
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                        if ("录入人".equals(companyNecessaryFieldVO.getFieldName())
                                || "录入方式".equals(companyNecessaryFieldVO.getFieldName())) {
                            companyNecessaryFieldVO.setIsDisabled(Boolean.TRUE);
                        }
                    }
                    break;
                case "基本信息":
                    //认证状态，默认未认证
                    boolean verified = false;
                    String empInfoId = companyNecessaryFieldQuery.getEmpInfoId();
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(empInfoId)) {
                        EmpInfoDO empInfoDO = empInfoService.selectById(empInfoId);
                        verified = empInfoDO.getVerified();
                    }

                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                        if ("身份证号".equals(companyNecessaryFieldVO.getFieldName()) ||
                                "姓名".equals(companyNecessaryFieldVO.getFieldName())) {
                            companyNecessaryFieldVO.setIsDisabled(verified);
                        }
                    }
                    break;
                default:
            }

            companyNecessaryModuleCodeVO.setFieldList(fieldList);
            //组装自定义字段
            List<CompanyAdditionalFieldsListVO> additionalFieldList = additionalFieldMap.get(moduleCode);
            if (additionalFieldList != null) {
                //自定义字段的英文名为id
                additionalFieldList.forEach(companyAdditionalFieldsListVO -> {
                    companyAdditionalFieldsListVO.setFieldCode(SafeKit.getString(companyAdditionalFieldsListVO.getId()));
                    // 自定义字段全部不禁用
                    companyAdditionalFieldsListVO.setIsDisabled(Boolean.FALSE);
                });
            }
            companyNecessaryModuleCodeVO.setAdditionalFieldList(additionalFieldList == null ? new ArrayList<>() : additionalFieldList);
            companyNecessaryModuleCodeList.add(companyNecessaryModuleCodeVO);
            if (!"家庭成员".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"紧急联系人".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"教育经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"工作经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"培训经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !CollectionUtils.isEmpty(companyNecessaryModuleCodeVO.getFieldList())) {
                companyNecessaryModuleCodeVO.setNecessary(companyNecessaryModuleCodeVO.getFieldList()
                        .parallelStream().anyMatch(CompanyNecessaryFieldVO::getIsNecessary));
            }
        });
        return companyNecessaryModuleCodeList;
    }

    /**
     * 设置工作性质
     * @param fieldList
     * @param tokenUser
     */
    public void setPostType(List<CompanyNecessaryFieldVO> fieldList, TokenUser tokenUser) {
        List<DictItemDO> list = adminProviderService.selectAllDictItem(null, POST_TYPE, tokenUser);
        List<DropDownEnumVO> dropDownEnumList1 = new ArrayList<>();
        for (DictItemDO dictItemDO : list) {
            DropDownEnumVO dropDownEnumVO = new DropDownEnumVO();
            dropDownEnumVO.setValue(dictItemDO.getDictItemValue());
            dropDownEnumVO.setLabel(dictItemDO.getDictItemKey());
            dropDownEnumList1.add(dropDownEnumVO);
        }

        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
            switch (companyNecessaryFieldVO.getFieldCode()) {
                case "postType":
                    //员工状态取数据库配置，不使用枚举类
                companyNecessaryFieldVO.setDropDownEnumList(dropDownEnumList1);
                break;
            }
        }
    }

    @Override
    public EmpFieldValueVO getEmpFieldValue(ModuleFieldQuery moduleFieldQuery, TokenUser tokenUser) {
        SiteVO site = adminProviderService.selectSiteById(tokenUser.getSiteId(), tokenUser);
        EmpFieldValueVO empFieldValueVO = new EmpFieldValueVO();
        String moduleCode = moduleFieldQuery.getModuleCode();
        String companyId = moduleFieldQuery.getCompanyId();
        //模块下的所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldList = this.selectByModuleCode(moduleCode, companyId, tokenUser.getSiteId());
        List<CompanyNecessaryFieldVO> fieldList = companyNecessaryFieldList.stream()
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class))
                .collect(Collectors.toList());
        //查询所有自定义字段
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectOpenByCompanyId(moduleFieldQuery.getCompanyId(), tokenUser.getSiteId());
        //所有自定义字段根据moduleCode分组
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        //员工填的值map
        List<EmpAdditionalFieldsDO> empValueList = empAdditionalFieldsService.selectByCompanyId(moduleFieldQuery.getEmpInfoId(),
                companyId, moduleCode, tokenUser.getSiteId());
        Map<Long, String> empValueMap = empValueList.parallelStream().filter(empAdditionalFieldsDO -> empAdditionalFieldsDO.getContent() != null)
                .collect(Collectors.toMap(EmpAdditionalFieldsDO::getFieldId, EmpAdditionalFieldsDO::getContent));
        String empId = moduleFieldQuery.getEmpInfoId();
        //获取员工信息
        EmpInfoVO empInfoVO = empInfoService.selectById(empId, tokenUser.getSiteId());
        //获取员工家庭信息
        List<EmpFamilyDO> empFamilyList = empFamilyService.listByEmpId(empId, tokenUser.getSiteId());
        //获取员工工作经历
        List<EmpWorkDO> empWorkList = empWorkService.listByEmpId(empId, tokenUser.getSiteId());
        //获取员工教育经历
        List<EmpEducationDO> empEducationList = empEducationService.listByEmpId(empId, tokenUser.getSiteId());
        //获取员工紧急联系人
        List<EmpContactsDO> empContactsList = empContactsService.listByEmpId(empId, tokenUser.getSiteId());
        //获取员工的奖惩记录
        List<EmpRewardPunishDO> empRewardPunish = empRewardPunishService.listByEmpId(empId, tokenUser.getSiteId());

        //获取员工培训经历
        List<EmpTrainDO> empTrainList = empTrainService.listByEmpId(empId, tokenUser.getSiteId());
        empFieldValueVO.setModuleCode(moduleCode);
        empFieldValueVO.setMultiple(EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode));
        if (empFieldValueVO.getMultiple()) {
            //多条字段的值设置需要通过不同的员工信息表
            switch (moduleCode) {
                case "empContacts":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processContactFieldList(fieldList, empContactsList));
                    break;
                case "empEducation":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processEducationFieldList(fieldList, empEducationList));
                    break;
                case "empFamily":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processFamilyFieldList(fieldList, empFamilyList));
                    break;
                case "empTrain":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processTrainFieldList(fieldList, empTrainList));
                    break;
                case "empWork":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processWorkFieldList(fieldList, empWorkList));
                    break;
                case "rewardsPunishments":
                    empFieldValueVO.setListData(EmpFieldModuleCodeKit.processRewardPunishList(fieldList, empRewardPunish));
                    break;
                default:
                    break;
            }
        } else {
            //其他字段的值全从员工表中取
            Map<String, String> dataMap = EmpFieldModuleCodeKit.processEmpFieldList(fieldList, empInfoVO);
            if (JIA_FANG_QY.equals(site.getSiteType()) || JIA_FANG_SY.equals(site.getSiteType())) {
                dataMap.remove("postType");
            }
            //组装自定义字段的值
            List<CompanyAdditionalFieldsListVO> additionalFieldList = additionalFieldMap.get(moduleCode);
            if (additionalFieldList != null) {
                additionalFieldList.forEach(companyAdditionalFieldsListVO ->
                        dataMap.put(SafeKit.getString(companyAdditionalFieldsListVO.getId())
                                , SafeKit.getString(empValueMap.get(companyAdditionalFieldsListVO.getId()))));
            }
            if (dataMap.size() != 0) {
                empFieldValueVO.setData(dataMap);
                try {
                    if ("socAndPf".equals(moduleFieldQuery.getModuleCode())) {
                        EmpImportSocRelatedDTO empSocRelated = empSocRelatedService.findEmpSocRelated(moduleFieldQuery.getEmpInfoId(), moduleFieldQuery.getCompanyId(), tokenUser);
                        if (empSocRelated != null) {
                            dataMap.put("startPaymentDate", StringUtils.isEmpty(empSocRelated.getStartPaymentDate()) ? null : empSocRelated.getStartPaymentDate());
                            dataMap.put("insuredCity", StringUtils.isEmpty(empSocRelated.getInsuredCity()) ? null : empSocRelated.getInsuredCity());
                        }
                    }
                } catch (Exception e) {
                    log.error("获取起缴时间或参保城市出错");
                }
            }
        }
        // 是否用POST请求
        boolean isPost = true;
        if (empFieldValueVO.getMultiple()) {
            if (!CollectionUtils.isEmpty(empFieldValueVO.getListData())) {
                isPost = false;
            }
        } else {
            if (Objects.nonNull(empFieldValueVO.getData())) {
                for (Map.Entry<String, String> entry : empFieldValueVO.getData().entrySet()) {
                    // 只要有一个数据不为空,就用PUT方法
                    if (Objects.nonNull(entry.getValue())) {
                        isPost = false;
                        break;
                    }
                }
            }
        }
        empFieldValueVO.setIsPost(isPost);
        return empFieldValueVO;
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public void updateEmpFieldValue(UpdateEmpFieldDTO updateEmpFieldDTO, HttpMethod httpMethod, Boolean isVerify, TokenUser tokenUser) {
        String moduleCode = updateEmpFieldDTO.getModuleCode();
        String companyId = updateEmpFieldDTO.getCompanyId();
        String empId = updateEmpFieldDTO.getEmpInfoId();
        Map<String, String> data = updateEmpFieldDTO.getData();
        //参数过滤空格
        for (String s : data.keySet()) {
            if (data.get(s) != null) {
                data.put(s, data.get(s).trim());
            }
        }

        log.info("员工修改动态表单接收数据：" + JSON.toJSONString(data));
        //模块下的所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldList = this.selectByModuleCode(moduleCode, companyId, tokenUser.getSiteId());
        List<CompanyNecessaryFieldVO> fieldList = companyNecessaryFieldList.stream()
                .filter(CompanyNecessaryFieldDO::getIsOpen)
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class))
                .collect(Collectors.toList());
        //正确字段的list
        List<String> rightFieldCode = fieldList.stream().map(CompanyNecessaryFieldVO::getFieldCode).collect(Collectors.toList());
        //校验字段必填
        List<String> notFillFieldList = new ArrayList<>();
        fieldList.forEach(companyNecessaryFieldVO -> {
            if (companyNecessaryFieldVO.getIsNecessary() && data.get(companyNecessaryFieldVO.getFieldCode()) == null) {
                notFillFieldList.add(companyNecessaryFieldVO.getFieldName());
            }
        });
        //查询所有自定义字段
        List<CompanyAdditionalFieldsVO> companyAdditionalFieldsVOList =
                companyAdditionalFieldsService.selectByCompanyAndModuleCode(companyId, moduleCode, tokenUser.getSiteId());
        //校验自定义字段必填
        companyAdditionalFieldsVOList.forEach(companyAdditionalFieldsVO -> {
            if (companyAdditionalFieldsVO.getIsNecessary() && data.get(SafeKit.getString(companyAdditionalFieldsVO.getId())) == null) {
                notFillFieldList.add(companyAdditionalFieldsVO.getFieldName());
            }
        });
        if (Boolean.TRUE.equals(isVerify)) {
            // 材料附件三个模块不校验必填
            if (!"annex".equals(moduleCode)
                    && !"archive".equals(moduleCode)
                    && !"leaveOffice".equals(moduleCode)) {
                ParamException.isTrue(notFillFieldList.isEmpty(), String.join(",", notFillFieldList) + "字段需要填写");
            }
        }
        rightFieldCode.addAll(companyAdditionalFieldsVOList.stream().map(CompanyAdditionalFieldsVO::getId).map(SafeKit::getString).collect(Collectors.toList()));

        //删除不合法的字段
        Map<String, String> dataMap = this.filterFieldMap(rightFieldCode, data);
        //自定义字段的id列表
        List<Long> additionFieldIdList = companyAdditionalFieldsVOList.stream()
                .map(CompanyAdditionalFieldsVO::getId)
                .collect(Collectors.toList());
        Boolean isMultiple = EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode);
        EmpInfoDO empInfo = empInfoService.selectDOById(empId, tokenUser.getSiteId());
        ParamException.notNull(empInfo, "未查询到员工信息，请刷新后重试");
        String oldPhone = empInfo.getPhone();
        String newPhone = data.get("phone");
        // 手机号最后在修改
        data.put("phone", oldPhone);

        String salaryCard = data.get("annexSalaryCard");
        // 读取银行卡号和银行名称
        if (StrKit.isNotEmpty(salaryCard)) {
            BankCardInfoVO bankInfo = getBankInfo(salaryCard, tokenUser);
            if (bankInfo != null) {
                data.put("bankCard", bankInfo.getBankCardNumber());
                data.put("bankName", bankInfo.getBankName());

                dataMap.put("bankCard", bankInfo.getBankCardNumber());
                dataMap.put("bankName", bankInfo.getBankName());
            }
        }

        if (isMultiple) {
            //处理员工关联表数据
            this.processEmpRelateTableData(moduleCode, empId, companyId, httpMethod, dataMap, tokenUser);
        } else {
            //获取员工信息
            EmpInfoUpdateDTO empInfoUpdateDTO = empInfo.to(EmpInfoUpdateDTO.class);
            //字段注入员工对象
            EmpFieldModuleCodeKit.processEmpFieldList(dataMap, empInfoUpdateDTO);
            empInfoUpdateDTO.setCheckApp(Boolean.TRUE);
            if (MODULE_REMARK.equals(moduleCode)) {
                String remark = data.get(MODULE_REMARK);
                if (StrKit.isNotEmpty(remark) && remark.length() > 200) {
                    throw new ParamException("备注不能超过200字");
                }
                empInfoUpdateDTO.setRemark(remark);
            }
            if (MODULE_TAG.equals(moduleCode)) {
                String tag = data.get(MODULE_TAG);
                if (StrKit.isNotEmpty(tag)) {
                    String[] array = tag.split(",");
                    if (array.length > 6) {
                        throw new ParamException("员工最多添加6个标签");
                    }
                }
                empInfoUpdateDTO.setTag(tag);
            }
            //修改员工表
            empInfoUpdateDTO.setPhone(oldPhone);

            empInfoService.update(empInfoUpdateDTO, tokenUser);

            // 修改工资卡信息或者附件上传修改工资卡都会发通知
            if (empInfoUpdateDTO.getBankName() != null
                    || (SALARY_CARD_CHANGE_MODULE_CODE.equals(moduleCode) && httpMethod.matches(HttpMethod.PUT.name()))) {
                EmpInfoDO empInfoChange = empInfoService.selectDOById(empId, tokenUser.getSiteId());
                // 发送消息
                try {
                    sendNoticeService.salaryChangeSendNotice(empInfoChange, companyId, tokenUser);
                } catch (Exception e) {
                    log.error("员工工资卡变更发送消息失败,{}", e.getMessage());
                }
            }
            //修改自定义字段表
            List<EmpAdditionalFieldsAddDTO> additionalFieldList = new ArrayList<>();
            // 字段id
            Map<Long, CompanyAdditionalFieldsVO> idCompanyAdditionalFieldsVO = companyAdditionalFieldsVOList.parallelStream()
                    .collect(Collectors.toMap(CompanyAdditionalFieldsVO::getId, v -> v));
            for (Long fieldId : additionFieldIdList) {
                CompanyAdditionalFieldsVO companyAdditionalFieldsVO = idCompanyAdditionalFieldsVO.get(fieldId);
                if (companyAdditionalFieldsVO != null) {
                    // 校验字段长度
                    checkFieldType(companyAdditionalFieldsVO.getFieldType(), companyAdditionalFieldsVO.getFieldName(),
                            dataMap.get(SafeKit.getString(fieldId)));
                }
                EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO = new EmpAdditionalFieldsAddDTO();
                empAdditionalFieldsAddDTO.setCompanyId(companyId);
                empAdditionalFieldsAddDTO.setEmpId(empId);
                empAdditionalFieldsAddDTO.setFieldId(fieldId);
                empAdditionalFieldsAddDTO.setModuleCode(moduleCode);
                empAdditionalFieldsAddDTO.setContent(dataMap.get(SafeKit.getString(fieldId)));
                //只更新传入的参数
                if (data.containsKey(String.valueOf(empAdditionalFieldsAddDTO.getFieldId()))) {
                    additionalFieldList.add(empAdditionalFieldsAddDTO);
                }
            }
            empAdditionalFieldsService.savePreDelete(empId, companyId, moduleCode, additionalFieldList, tokenUser);
        }
        CompanyDO companyDO = companyService.selectDOById(empInfo.getCompanyId(), tokenUser.getSiteId());
        if ("contact".equals(updateEmpFieldDTO.getModuleCode()) && newPhone != null && !oldPhone.equals(newPhone)) {
            // 修改手机号
            empInfoService.updatePhone(oldPhone, newPhone, tokenUser);
        }

        HrLogKit.logForSave("由管理员" + tokenUser.getUserName() + "修改员工信息,员工姓名:" + empInfo.getName() +
                "所在公司:" + companyDO.getName(), "empInfo", empInfo.getId(), tokenUser);
    }

    /**
     * 读取银行卡信息，从第一张开始读取，读取到信息就返回
     * 只要读取到信息返回值一定不是null
     */
    private BankCardInfoVO getBankInfo(String salaryCard, TokenUser tokenUser) {
        // 读取银行卡号和银行名称
        if (StrKit.isEmpty(salaryCard)) {
            return null;
        }
        List<String> list = ArrayKit.split(salaryCard, ",");
        // 从最后一张开始读取
        Collections.reverse(list);
        for (String url : list) {
            BankCardInfoVO bankcard = fileProviderService.bankcard(url, tokenUser);
            // 银行卡类型，0：不能识别; 1：借记卡; 2：贷记卡（原信用卡大部分为贷记卡）; 3：准贷记卡; 4：预付费卡
            if (Objects.equals(0, bankcard.getBankCardType())) {
                continue;
            }
            String bankName = bankcard.getBankName();
            // 去除银行卡中的空格
            String bankCardNumber = bankcard.getBankCardNumber() == null ? bankcard.getBankCardNumber()
                    : bankcard.getBankCardNumber().replaceAll(" ", "");
            bankcard.setBankCardNumber(bankCardNumber);
            if (StrKit.isNotEmpty(bankCardNumber) || StrKit.isNotEmpty(bankName)) {
                return bankcard;
            }
        }
        return null;
    }

    /**
     * 校验字段长度
     *
     * @param fieldType 字段类型
     * @param fieldName 字段名称
     * @param content   字段内容
     */
    private void checkFieldType(Integer fieldType, String fieldName, String content) {
        if (content == null) {
            return;
        }
        if (HrConstants.FIELD_TYPE_TEXT.equals(fieldType)) {
            if (content.length() > 50) {
                throw new ParamException("【" + fieldName + "】长度不能超过50");
            }
        } else if (HrConstants.FIELD_TYPE_TEXTAREA.equals(fieldType)) {
            if (content.length() > 200) {
                throw new ParamException("【" + fieldName + "】长度不能超过200");
            }
        }
    }


    /**
     * 发送短信
     */
    /*private void sendSms(List<HrUserVO> userVOList, TokenUser tokenUser) {
        for (HrUserVO hrUserVO : userVOList) {
            String thirdId = siteConfigProviderService.selectValueByCode(ConfigCodeConstants.CODE_SMS_TEMPLATE_ID, tokenUser.getSiteId());
            // 短信通知
            ShortMessageDTO shortMessageDTO = new ShortMessageDTO();
            shortMessageDTO.setScene("企业公告");
            shortMessageDTO.setThirdId(thirdId);
            // 写入短信内容
            long startTime = System.currentTimeMillis();
            // 阿里云批量发送上限为1000
            shortMessageDTO.setPhone(hrUserVO.getPhone());
            shortMessageDTO.setScene("此处需要配置短信场景");
            messageProviderService.sendShortMessage(shortMessageDTO, tokenUser);
        }
    }*/


    /**
     * 发送邮件
     */
    private void sendEmail(List<HrUserVO> userVOList, TokenUser tokenUser) {

    }


    @Override
    public void checkEmpFieldValue(String empId, String companyId, TokenUser tokenUser) {
        //查询moduleCode是否必填
        List<CompanyEmpNecessaryVO> moduleCodeList = companyEmpNecessaryService.selectByCompanyId(companyId, tokenUser);
        //必填的moduleCode
        List<String> needCompleteModuleList = moduleCodeList.stream()
                .filter(CompanyEmpNecessaryVO::getIsNecessary)
                .map(CompanyEmpNecessaryVO::getModuleCode)
                .collect(Collectors.toList());
        //校验顺序
        List<String> checkSortModuleList = EmpFieldModuleCodeKit.getAllModuleCodeList();
        //查询所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = this.selectCompanyAllNeedCheckField(companyId, tokenUser.getSiteId());
        Map<String, List<CompanyNecessaryFieldDO>> fieldMap = companyNecessaryFieldDOList.stream()
                .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getModuleCode));
        List<String> needCompleteFieldList = new ArrayList<>();
        //查询所有自定义字段
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectByCompanyId(companyId, tokenUser.getSiteId());
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        //员工填的值map
        List<EmpAdditionalFieldsDO> empValueList = empAdditionalFieldsService.selectByCompanyId(empId,
                companyId, null, tokenUser.getSiteId());
        Map<Long, String> empValueMap = empValueList.parallelStream().filter(empAdditionalFieldsDO -> empAdditionalFieldsDO.getContent() != null)
                .collect(Collectors.toMap(EmpAdditionalFieldsDO::getFieldId, EmpAdditionalFieldsDO::getContent));
        //查询员工对象
        EmpInfoDO empInfoDO = empInfoService.selectDOById(empId, tokenUser.getSiteId());
        //按顺序校验
        for (String moduleCode : checkSortModuleList) {
            //从关联表中取,校验模块是否必填
            this.checkEmpRelateTableNecessary(moduleCode, needCompleteModuleList, empId, tokenUser);
            List<CompanyNecessaryFieldDO> fieldList = fieldMap.get(moduleCode);
            // 模块下必填字段为空 跳过
            if (CollectionUtils.isEmpty(fieldList)) {
                continue;
            }
            //先校验固有字段
            for (CompanyNecessaryFieldDO companyNecessaryFieldDO : fieldList) {
                if (companyNecessaryFieldDO.getIsNecessary()) {
                    //从员工表中取
                    if (!EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode)) {
                        try {
                            Object value = ClassKit.getValue(empInfoDO, companyNecessaryFieldDO.getFieldCode());
                            if (value == null) {
                                needCompleteFieldList.add(companyNecessaryFieldDO.getFieldName());
                            }
                        } catch (Exception e) {
                            log.error("员工表未找到" + companyNecessaryFieldDO.getFieldName() + "字段!");
                        }
                    } else {
                        //从关联表中取
                        this.checkEmpRelateTableNecessary(moduleCode, needCompleteModuleList, empId, tokenUser);
                    }
                }
            }
            //校验自定义字段
            List<CompanyAdditionalFieldsListVO> additionalFieldsList = additionalFieldMap.get(moduleCode);
            if (!CollectionUtils.isEmpty(additionalFieldsList)) {
                for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO : additionalFieldsList) {
                    if (companyAdditionalFieldsListVO.getIsNecessary() && empValueMap.get(companyAdditionalFieldsListVO.getId()) == null) {
                        needCompleteFieldList.add(companyAdditionalFieldsListVO.getFieldName());
                    }
                }
            }
            ParamException.isTrue(needCompleteFieldList.isEmpty(), EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) +
                    "模块：" + String.join(",", needCompleteFieldList) + "需要填写");
        }
    }

    /**
     * 校验员工关联表必填
     *
     * @param moduleCode             模块code
     * @param needCompleteModuleList 校验必填的模块
     * @param empId                  员工id
     * @param tokenUser              当前登录用户
     */
    private void checkEmpRelateTableNecessary(String moduleCode, List<String> needCompleteModuleList, String empId, TokenUser tokenUser) {
        //从关联表中取
        switch (moduleCode) {
            case "empContacts":
                if (!needCompleteModuleList.contains(moduleCode)) {
                    break;
                }
                //获取员工紧急联系人
                List<EmpContactsDO> empContactsList = empContactsService.listByEmpId(empId, tokenUser.getSiteId());
                if (CollectionUtils.isEmpty(empContactsList)) {
                    throw new ParamException(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) + "需要填写");
                }
                break;
            case "empEducation":
                if (!needCompleteModuleList.contains(moduleCode)) {
                    break;
                }
                //获取员工教育经历
                List<EmpEducationDO> empEducationList = empEducationService.listByEmpId(empId, tokenUser.getSiteId());
                if (CollectionUtils.isEmpty(empEducationList)) {
                    throw new ParamException(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) + "需要填写");
                }
                break;
            case "empFamily":
                if (!needCompleteModuleList.contains(moduleCode)) {
                    break;
                }
                //获取员工家庭信息
                List<EmpFamilyDO> empFamilyList = empFamilyService.listByEmpId(empId, tokenUser.getSiteId());
                if (CollectionUtils.isEmpty(empFamilyList)) {
                    throw new ParamException(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) + "需要填写");
                }
                break;
            case "empTrain":
                if (!needCompleteModuleList.contains(moduleCode)) {
                    break;
                }
                //获取员工培训经历
                List<EmpTrainDO> empTrainList = empTrainService.listByEmpId(empId, tokenUser.getSiteId());
                if (CollectionUtils.isEmpty(empTrainList)) {
                    throw new ParamException(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) + "需要填写");
                }
                break;
            case "empWork":
                if (!needCompleteModuleList.contains(moduleCode)) {
                    break;
                }
                //获取员工工作经历
                List<EmpWorkDO> empWorkList = empWorkService.listByEmpId(empId, tokenUser.getSiteId());
                if (CollectionUtils.isEmpty(empWorkList)) {
                    throw new ParamException(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode) + "需要填写");
                }
                break;
            default:
                break;
        }
    }

    /**
     * 将前端传入的字段kv过滤掉不合法的字段
     *
     * @param fieldList 应该含有的字段list
     * @param dataMap   前端传入的map
     * @return 正确的kv
     */
    private Map<String, String> filterFieldMap(List<String> fieldList, Map<String, String> dataMap) {
        Map<String, String> filteredMap = new HashMap<>();
        dataMap.forEach((k, v) -> {
            if (fieldList.contains(k) || "id".equals(k)) {
                filteredMap.put(k, v);
            }
        });
        return filteredMap;
    }

    /**
     * 小程序修改员工动态表单处理员工关联表
     *
     * @param moduleCode 模块code
     * @param httpMethod http方法
     * @param data       数据map
     * @param tokenUser  当前登录用户
     */
    private void processEmpRelateTableData(String moduleCode, String empId, String companyId, HttpMethod httpMethod, Map<String, String> data, TokenUser tokenUser) {
        switch (moduleCode) {
            case "empContacts":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    EmpContactsUpdateDTO empContactsUpdateDTO = JSON.parseObject(JSON.toJSONString(data), EmpContactsUpdateDTO.class);
                    empContactsService.update(empContactsUpdateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpContactsAddDTO addDTO = JSON.parseObject(JSON.toJSONString(data), EmpContactsAddDTO.class);
                    addDTO.setEmpId(empId);
                    addDTO.setCompanyId(companyId);
                    empContactsService.save(addDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empContactsService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            case "empEducation":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要修改的数据");
                    EmpEducationUpdateDTO empEducationUpdateDTO = JSON.parseObject(JSON.toJSONString(data), EmpEducationUpdateDTO.class);
                    empEducationUpdateDTO.setEmpId(empId);
                    empEducationService.update(empEducationUpdateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpEducationAddDTO addDTO = JSON.parseObject(JSON.toJSONString(data), EmpEducationAddDTO.class);
                    addDTO.setEmpId(empId);
                    addDTO.setCompanyId(companyId);
                    empEducationService.save(addDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empEducationService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            case "empFamily":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    EmpFamilyUpdateDTO updateDTO = JSON.parseObject(JSON.toJSONString(data), EmpFamilyUpdateDTO.class);
                    empFamilyService.update(updateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpFamilyAddDTO addDTO = JSON.parseObject(JSON.toJSONString(data), EmpFamilyAddDTO.class);
                    addDTO.setEmpId(empId);
                    addDTO.setCompanyId(companyId);
                    empFamilyService.save(addDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empFamilyService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            case "empTrain":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    EmpTrainUpdateDTO updateDTO = JSON.parseObject(JSON.toJSONString(data), EmpTrainUpdateDTO.class);
                    empTrainService.update(updateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpTrainAddDTO addDTO = JSON.parseObject(JSON.toJSONString(data), EmpTrainAddDTO.class);
                    addDTO.setEmpId(empId);
                    addDTO.setCompanyId(companyId);
                    empTrainService.save(addDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empTrainService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            case "empWork":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    EmpWorkUpdateDTO updateDTO = JSON.parseObject(JSON.toJSONString(data), EmpWorkUpdateDTO.class);
                    empWorkService.update(updateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpWorkAddDTO addDTO = JSON.parseObject(JSON.toJSONString(data), EmpWorkAddDTO.class);
                    addDTO.setEmpId(empId);
                    addDTO.setCompanyId(companyId);
                    empWorkService.save(addDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empWorkService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            //奖惩记录，单独更新
            case "rewardsPunishments":
                if (httpMethod.matches(HttpMethod.PUT.name())) {
                    ParamException.notNull(data.get("id"), "请选择要更新的数据");
                    EmpRewardPunishUpdateDTO empRewardPunishUpdateDTO =
                            JSON.parseObject(JSON.toJSONString(data), EmpRewardPunishUpdateDTO.class);
                    empRewardPunishUpdateDTO.setCompanyId(companyId);
                    empRewardPunishUpdateDTO.setEmpId(empId);
                    empRewardPunishService.update(empRewardPunishUpdateDTO, tokenUser);
                } else if (httpMethod.matches(HttpMethod.POST.name())) {
                    EmpRewardPunishAddDTO empRewardPunishAddDTO =
                            JSON.parseObject(JSON.toJSONString(data), EmpRewardPunishAddDTO.class);
                    empRewardPunishAddDTO.setCompanyId(companyId);
                    empRewardPunishAddDTO.setEmpId(empId);
                    empRewardPunishService.save(empRewardPunishAddDTO, tokenUser);
                } else {
                    ParamException.notNull(data.get("id"), "请选择要删除的数据");
                    empRewardPunishService.deleteByIds(tokenUser, data.get("id"));
                }
                break;
            default:
                break;
        }
    }


    @Override
    public CompanyFieldAndValueListVO listAllForApp(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        if (companyNecessaryFieldQuery.getEmpInfoId() == null) {
            throw new ParamException("员工id不能为空");
        }
        CompanyFieldAndValueListVO companyFieldAndValueListVO = new CompanyFieldAndValueListVO();
        companyNecessaryFieldQuery.setIsOpen(true);
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        /*if (selectIsEmptyByCompanyId(companyNecessaryFieldQuery.getCompanyId())) {
            //空的时候创建一套
            necessaryInitializationByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
            //然后重新查一下
            return listAllForApp(companyNecessaryFieldQuery, tokenUser);
        }*/
        //查询当前登录用户的相关的内容
        List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
            CompanyNecessaryFieldVO companyNecessaryFieldVO = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
            companyNecessaryFieldVOList.add(companyNecessaryFieldVO);
        }
        CompanyAdditionalFieldsQuery companyAdditionalFieldsQuery = new CompanyAdditionalFieldsQuery();
        if (companyNecessaryFieldQuery.getModuleCode() != null) {
            companyAdditionalFieldsQuery.setModuleCode(companyNecessaryFieldQuery.getModuleCode());
        }
        if (companyNecessaryFieldQuery.getCompanyId() != null) {
            companyAdditionalFieldsQuery.setCompanyId(companyNecessaryFieldQuery.getCompanyId());
        }
        if (companyNecessaryFieldQuery.getIsNecessary() != null) {
            companyAdditionalFieldsQuery.setIsNecessary(companyNecessaryFieldQuery.getIsNecessary());
        }
        if (companyNecessaryFieldQuery.getIsOpen() != null) {
            companyAdditionalFieldsQuery.setIsOpen(companyNecessaryFieldQuery.getIsOpen());
        }
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.select(companyAdditionalFieldsQuery, tokenUser.getSiteId());
        Map<String, List<CompanyAdditionalFieldsListVO>> companyAdditionalFieldsListMap =
                companyAdditionalFieldsListVOList.stream().collect(
                        Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        Map<String, List<CompanyNecessaryFieldVO>> companyNecessaryFieldMap = companyNecessaryFieldVOList.stream()
                .collect(Collectors.groupingBy(CompanyNecessaryFieldVO::getModuleCode));
        CompanyFieldForPcListVO companyFieldForPcListVO = new CompanyFieldForPcListVO();
        complete(companyFieldForPcListVO, companyAdditionalFieldsListMap, companyNecessaryFieldMap);
        companyFieldAndValueListVO = companyFieldForPcListVO.to(CompanyFieldAndValueListVO.class);
        //插入数据
        addValue(companyFieldAndValueListVO, tokenUser, companyNecessaryFieldQuery.getEmpInfoId());
        addBasicValue(companyFieldAndValueListVO, tokenUser, companyNecessaryFieldQuery.getEmpInfoId(), companyNecessaryFieldMap);
        listForShow("basic", companyFieldAndValueListVO);
        listForShow("empEducation", companyFieldAndValueListVO);
        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOList =
                companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        // 处理顺序：紧急联系人-教育经历-家庭成员-培训经历-工作经历
        List<CompanyEmpNecessaryVO> empNecessaryVOS = new ArrayList<>();
        for (CompanyEmpNecessaryVO companyEmpNecessaryVO : companyEmpNecessaryVOList) {
            switch (companyEmpNecessaryVO.getModuleName()) {
                case "紧急联系人":
                    companyEmpNecessaryVO.setSort(1);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "教育经历":
                    companyEmpNecessaryVO.setSort(2);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "家庭成员":
                    companyEmpNecessaryVO.setSort(3);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "培训经历":
                    companyEmpNecessaryVO.setSort(4);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
                case "工作经历":
                    companyEmpNecessaryVO.setSort(5);
                    empNecessaryVOS.add(companyEmpNecessaryVO);
                    break;
            }
        }
        empNecessaryVOS.sort(Comparator.comparingInt(CompanyEmpNecessaryVO::getSort));
        companyFieldAndValueListVO.setCompanyEmpNecessaryVOList(empNecessaryVOS);
        return companyFieldAndValueListVO;
    }

    @Override
    public List<CompanyFieldAndValueListVO> listAllForApp2(CompanyNecessaryFieldQuery companyNecessaryFieldQuery,
                                                           List<String> empIdList, TokenUser tokenUser) {

        List<CompanyFieldAndValueListVO> valueListVOS = new ArrayList<>();
        companyNecessaryFieldQuery.setIsOpen(true);
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());


        CompanyAdditionalFieldsQuery companyAdditionalFieldsQuery = new CompanyAdditionalFieldsQuery();
        if (companyNecessaryFieldQuery.getModuleCode() != null) {
            companyAdditionalFieldsQuery.setModuleCode(companyNecessaryFieldQuery.getModuleCode());
        }
        if (companyNecessaryFieldQuery.getCompanyId() != null) {
            companyAdditionalFieldsQuery.setCompanyId(companyNecessaryFieldQuery.getCompanyId());
        }
        if (companyNecessaryFieldQuery.getIsNecessary() != null) {
            companyAdditionalFieldsQuery.setIsNecessary(companyNecessaryFieldQuery.getIsNecessary());
        }
        if (companyNecessaryFieldQuery.getIsOpen() != null) {
            companyAdditionalFieldsQuery.setIsOpen(companyNecessaryFieldQuery.getIsOpen());
        }
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.select(companyAdditionalFieldsQuery, tokenUser.getSiteId());
        Map<String, List<CompanyAdditionalFieldsListVO>> companyAdditionalFieldsListMap =
                companyAdditionalFieldsListVOList.stream().collect(
                        Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));

        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOList =
                companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        for (String empId : empIdList) {

            CompanyFieldAndValueListVO companyFieldAndValueListVO;
            //查询当前登录用户的相关的内容
            List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
            for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                CompanyNecessaryFieldVO companyNecessaryFieldVO = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                companyNecessaryFieldVOList.add(companyNecessaryFieldVO);
            }


            Map<String, List<CompanyNecessaryFieldVO>> companyNecessaryFieldMap = companyNecessaryFieldVOList.stream()
                    .collect(Collectors.groupingBy(CompanyNecessaryFieldVO::getModuleCode));
            CompanyFieldForPcListVO companyFieldForPcListVO = new CompanyFieldForPcListVO();
            complete(companyFieldForPcListVO, companyAdditionalFieldsListMap, companyNecessaryFieldMap);
            companyFieldAndValueListVO = companyFieldForPcListVO.to(CompanyFieldAndValueListVO.class);
            //插入数据
            CompanyFieldAndValueListVO valueVO = addValue(companyFieldAndValueListVO, tokenUser, empId);
            addBasicValue(valueVO, tokenUser, empId, companyNecessaryFieldMap);
            listForShow("companyFieldAndValueListVO: ", companyFieldAndValueListVO);
            // 处理顺序：紧急联系人-教育经历-家庭成员-培训经历-工作经历
            List<CompanyEmpNecessaryVO> empNecessaryVOS = new ArrayList<>();
            for (CompanyEmpNecessaryVO companyEmpNecessaryVO : companyEmpNecessaryVOList) {
                switch (companyEmpNecessaryVO.getModuleName()) {
                    case "紧急联系人":
                        companyEmpNecessaryVO.setSort(1);
                        empNecessaryVOS.add(companyEmpNecessaryVO);
                        break;
                    case "教育经历":
                        companyEmpNecessaryVO.setSort(2);
                        empNecessaryVOS.add(companyEmpNecessaryVO);
                        break;
                    case "家庭成员":
                        companyEmpNecessaryVO.setSort(3);
                        empNecessaryVOS.add(companyEmpNecessaryVO);
                        break;
                    case "培训经历":
                        companyEmpNecessaryVO.setSort(4);
                        empNecessaryVOS.add(companyEmpNecessaryVO);
                        break;
                    case "工作经历":
                        companyEmpNecessaryVO.setSort(5);
                        empNecessaryVOS.add(companyEmpNecessaryVO);
                        break;
                }
            }
            empNecessaryVOS.sort(Comparator.comparingInt(CompanyEmpNecessaryVO::getSort));
            valueVO.setCompanyEmpNecessaryVOList(empNecessaryVOS);
            valueVO.setEmpId(empId);
            valueListVOS.add(valueVO);
        }
        return valueListVOS;
    }

    @Override
    public List<String> listNecessaryModeForApp(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        List<String> returnList = new ArrayList<>();
        companyNecessaryFieldQuery.setIsOpen(true);
        companyNecessaryFieldQuery.setIsNecessary(true);
        if (companyNecessaryFieldQuery.getCompanyId() == null) {
            throw new ParamException("公司id不能为空");
        }
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(companyNecessaryFieldDOList)) {
            Map<String, List<CompanyNecessaryFieldDO>> map =
                    companyNecessaryFieldDOList.parallelStream()
                            .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getModuleCode));
            for (String key : map.keySet()) {
                if ("empContacts".equals(key) ||
                        "empEducation".equals(key) ||
                        "empFamily".equals(key) ||
                        "empTrain".equals(key) || "empWork".equals(key)) {
                    continue;
                } else {
                    returnList.add(key);
                }

            }
        }
        return returnList;
    }

    @Override
    public List<CompanyNecessaryFieldVO> listForAppModule(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        if (companyNecessaryFieldQuery.getEmpInfoId() == null) {
            throw new ParamException("员工id不能为空");
        }
        if (companyNecessaryFieldQuery.getModuleCode() == null) {
            throw new ParamException("模块类型不能为空");
        }
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());
        List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
        addValueToApp(companyNecessaryFieldDOList, companyNecessaryFieldVOList, companyNecessaryFieldQuery, tokenUser);
        CompanyFieldAndValueListVO companyFieldAndValueListVO = new CompanyFieldAndValueListVO();
        if ("empEducation".equals(companyNecessaryFieldQuery.getModuleCode())) {
            List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryEducationVOList = new ArrayList<>();
            companyEmpNecessaryEducationVOList.add(companyNecessaryFieldVOList);
            companyFieldAndValueListVO.setCompanyEmpNecessaryEducationVOList(companyEmpNecessaryEducationVOList);
            listForShow("empEducation", companyFieldAndValueListVO);
            companyNecessaryFieldVOList =
                    companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList().get(0);
        }
        return companyNecessaryFieldVOList;
    }

    /**
     * app端
     *
     * @param companyNecessaryFieldDOList 原装
     * @param companyNecessaryFieldVOList 展示
     * @param companyNecessaryFieldQuery  条件
     */
    private void addValueToApp(List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList,
                               List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList,
                               CompanyNecessaryFieldQuery companyNecessaryFieldQuery,
                               TokenUser tokenUser) {
        if (!CollectionUtils.isEmpty(companyNecessaryFieldDOList)) {
            for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                CompanyNecessaryFieldVO companyNecessaryFieldVO = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                if (companyNecessaryFieldQuery.getId() != null) {
                    switch (companyNecessaryFieldQuery.getModuleCode()) {
                        case "empContacts":
                            EmpContactsVO empContactsVO =
                                    empContactsService.selectById(companyNecessaryFieldQuery.getId(), tokenUser.getSiteId());
                            if (empContactsVO != null) {
                                companyNecessaryFieldVO.setEmpContactsListVO(empContactsVO.to(EmpContactsListVO.class));
                            }
                            break;
                        case "empEducation":
                            EmpEducationVO empEducationVO = empEducationService.selectById(companyNecessaryFieldQuery.getId(), tokenUser.getSiteId());
                            companyNecessaryFieldVO.setEmpEducationVO(empEducationVO);
                            break;
                        case "empFamily":
                            EmpFamilyVO empFamilyVO = empFamilyService.selectById(companyNecessaryFieldQuery.getId(), tokenUser.getSiteId());
                            companyNecessaryFieldVO.setEmpFamilyVO(empFamilyVO);
                            break;
                        case "empTrain":
                            EmpTrainVO empTrainVO = empTrainService.selectById(companyNecessaryFieldQuery.getId(), tokenUser.getSiteId());
                            if (empTrainVO != null) {
                                EmpTrainListVO empTrainListVO = empTrainVO.to(EmpTrainListVO.class);
                                companyNecessaryFieldVO.setEmpTrainListVO(empTrainListVO);
                            }
                            break;
                        case "empWork":
                            EmpWorkVO empWorkVO = empWorkService.selectById(companyNecessaryFieldQuery.getId(), tokenUser.getSiteId());
                            if (empWorkVO != null) {
                                EmpWorkListVO empWorkListVO = empWorkVO.to(EmpWorkListVO.class);
                                companyNecessaryFieldVO.setEmpWorkListVO(empWorkListVO);
                            }
                            break;
                        default:
                            break;
                    }
                }
                companyNecessaryFieldVOList.add(companyNecessaryFieldVO);
            }
        }
    }

    /**
     * 下拉框数组完成
     *
     * @param type                       模块类型
     * @param companyFieldAndValueListVO 实体
     */
    private void listForShow(String type, CompanyFieldAndValueListVO companyFieldAndValueListVO) {
        switch (type) {
            case "basic":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList()) {
                        switch (companyNecessaryFieldVO.getFieldCode()) {
                            case "gender":
                                List<String> list9 = new ArrayList<>();
                                //性别
                                list9.add("男");
                                list9.add("女");
                                companyNecessaryFieldVO.setListOfShow(list9);
                                break;
                            case "bloodGroup":
                                List<String> list3 = new ArrayList<>();
                                //血型
                                list3.add("A");
                                list3.add("B");
                                list3.add("AB");
                                list3.add("O");
                                list3.add("其他");
                                companyNecessaryFieldVO.setListOfShow(list3);
                                break;
                            case "politicalStatus":
                                List<String> list4 = new ArrayList<>();
                                //政治面貌
                                list4.add("中共党员");
                                list4.add("共青团员");
                                list4.add("普通居民/群众");
                                list4.add("其他");
                                companyNecessaryFieldVO.setListOfShow(list4);
                                break;
                            case "nation":
                                String a = "汉族,满族,蒙古族,回族,藏族,维吾尔族,苗族,彝族,壮族,布依族,侗族,瑶族,白族,土家族,哈尼族,哈萨克族,傣族,黎族,傈僳族,佤族,畲族,高山族,拉祜族,水族,东乡族,纳西族,景颇族,柯尔克孜族,土族,达斡尔族,仫佬族,羌族,布朗族,撒拉族,毛南族,仡佬族,锡伯族,阿昌族,普米族,朝鲜族,塔吉克族,怒族,乌孜别克族,俄罗斯族,鄂温克族,德昂族,保安族,裕固族,京族,塔塔尔族,独龙族,鄂伦春族,赫哲族,门巴族,珞巴族,基诺族";
                                List<String> list5 = new ArrayList<>();
                                //民族
                                list5 = Arrays.asList(a.split(","));
                                companyNecessaryFieldVO.setListOfShow(list5);
                                break;
                            case "regType":
                                List<String> list6 = new ArrayList<>();
                                //户口类型
                                list6.add("城镇户口");
                                list6.add("农村户口");
                                list6.add("居民户口");
                                companyNecessaryFieldVO.setListOfShow(list6);
                                break;
                            case "birthStatus":
                                List<String> list7 = new ArrayList<>();
                                //生育状况
                                list7.add("已生育");
                                list7.add("未生育");
                                companyNecessaryFieldVO.setListOfShow(list7);
                                break;
                            case "maritalStatus":
                                List<String> list8 = new ArrayList<>();
                                //婚姻状况
                                list8.add("已婚");
                                list8.add("未婚");
                                list8.add("离异");
                                companyNecessaryFieldVO.setListOfShow(list8);
                                break;
                            default:
                                break;
                        }
                    }
                }
                break;
            case "empEducation":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList())) {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            switch (companyNecessaryFieldVO.getFieldCode()) {
                                case "degreeType":
                                    List<String> list1 = new ArrayList<>();
                                    //学位类型
                                    list1.add("学士");
                                    list1.add("硕士");
                                    list1.add("博士");
                                    list1.add("未获得学位");
                                    companyNecessaryFieldVO.setListOfShow(list1);
                                    break;
                                case "education":
                                    List<String> list = new ArrayList<>();
                                    //学历
                                    list.add("小学");
                                    list.add("初中");
                                    list.add("中专");
                                    list.add("高中");
                                    list.add("大专");
                                    list.add("本科");
                                    list.add("硕士");
                                    list.add("博士");
                                    list.add("其他");
                                    companyNecessaryFieldVO.setListOfShow(list);
                                    break;
                                case "teaMethods":
                                    List<String> list2 = new ArrayList<>();
                                    //学习形式
                                    list2.add("全日制");
                                    list2.add("成人教育");
                                    list2.add("远程教育");
                                    list2.add("自学考试");
                                    list2.add("其他非全日制");
                                    companyNecessaryFieldVO.setListOfShow(list2);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
                break;
            default:
                break;
        }
    }

    private void addBasicValue(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser,
                               String empInfoId, Map<String, List<CompanyNecessaryFieldVO>> companyNecessaryFieldMap) {
        EmpInfoVO empInfoVO = empInfoService.selectById(empInfoId, tokenUser.getSiteId());
        //公司员工基本信息
        if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工社保公积金信息
        if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessarySocAndPfVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessarySocAndPfVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工家庭成员信息
        List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryFamilyMembersVOList = new ArrayList<>();
        List<EmpFamilyDO> empFamilyList = empFamilyService.listByEmpId(empInfoId, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(empFamilyList)) {
            for (EmpFamilyDO empFamilyDO : empFamilyList) {
                List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
                if (companyNecessaryFieldMap.get("empFamily") != null) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldMap.get("empFamily")) {
                        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldVO.to(CompanyNecessaryFieldDO.class);
                        CompanyNecessaryFieldVO companyNecessaryFieldVO1 = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                        companyNecessaryFieldVO1.setEmpFamilyVO(empFamilyDO.to((EmpFamilyVO.class)));
                        companyNecessaryFieldVOList.add(companyNecessaryFieldVO1);
                    }
                }
                companyEmpNecessaryFamilyMembersVOList.add(companyNecessaryFieldVOList);
            }
        }
        companyFieldAndValueListVO.setCompanyEmpNecessaryFamilyMembersVOList(companyEmpNecessaryFamilyMembersVOList);
        //公司员工联系人所需信息
        if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工工作经历所需信息
        List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryWorkVOList = new ArrayList<>();
        List<EmpWorkDO> empWorkList = empWorkService.listByEmpId(empInfoId, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(empWorkList)) {
            for (EmpWorkDO empWorkDO : empWorkList) {
                List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
                if (companyNecessaryFieldMap.get("empWork") != null) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldMap.get("empWork")) {
                        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldVO.to(CompanyNecessaryFieldDO.class);
                        CompanyNecessaryFieldVO companyNecessaryFieldVO1 = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                        companyNecessaryFieldVO1.setEmpWorkListVO(empWorkDO.to(EmpWorkListVO.class));
                        companyNecessaryFieldVOList.add(companyNecessaryFieldVO1);
                    }
                }
                companyEmpNecessaryWorkVOList.add(companyNecessaryFieldVOList);
            }
        }
        companyFieldAndValueListVO.setCompanyEmpNecessaryWorkVOList(companyEmpNecessaryWorkVOList);
        // 公司员工教育经历所需信息
        List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryEducationVOList = new ArrayList<>();
        List<EmpEducationDO> empEducationList = empEducationService.listByEmpId(empInfoId, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(empEducationList)) {
            for (EmpEducationDO empEducationDO : empEducationList) {
                List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
                if (companyNecessaryFieldMap.get("empEducation") != null) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldMap.get("empEducation")) {
                        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldVO.to(CompanyNecessaryFieldDO.class);
                        CompanyNecessaryFieldVO companyNecessaryFieldVO1 = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                        companyNecessaryFieldVO1.setEmpEducationVO(empEducationDO.to(EmpEducationVO.class));
                        companyNecessaryFieldVOList.add(companyNecessaryFieldVO1);
                    }
                }
                companyEmpNecessaryEducationVOList.add(companyNecessaryFieldVOList);
            }
        }
        companyFieldAndValueListVO.setCompanyEmpNecessaryEducationVOList(companyEmpNecessaryEducationVOList);
        //公司员工紧急联系人所需信息
        List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryEmergencyContactVOList = new ArrayList<>();
        List<EmpContactsDO> empContactsList = empContactsService.listByEmpId(empInfoId, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(empContactsList)) {
            for (EmpContactsDO empContactsDO : empContactsList) {
                List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
                if (companyNecessaryFieldMap.get("empContacts") != null) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldMap.get("empContacts")) {
                        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldVO.to(CompanyNecessaryFieldDO.class);
                        CompanyNecessaryFieldVO companyNecessaryFieldVO1 = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                        companyNecessaryFieldVO1.setEmpContactsListVO(empContactsDO.to(EmpContactsListVO.class));
                        companyNecessaryFieldVOList.add(companyNecessaryFieldVO1);
                    }
                }
                companyEmpNecessaryEmergencyContactVOList.add(companyNecessaryFieldVOList);
            }
        }
        companyFieldAndValueListVO.setCompanyEmpNecessaryEmergencyContactVOList(companyEmpNecessaryEmergencyContactVOList);
        //公司员工培训记录所需信息
        List<List<CompanyNecessaryFieldVO>> companyEmpNecessaryTrainVOList = new ArrayList<>();
        List<EmpTrainDO> empTrainList = empTrainService.listByEmpId(empInfoId, tokenUser.getSiteId());
        if (!CollectionUtils.isEmpty(empTrainList)) {
            for (EmpTrainDO empTrainDO : empTrainList) {
                List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList = new ArrayList<>();
                if (companyNecessaryFieldMap.get("empTrain") != null) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldMap.get("empTrain")) {
                        CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldVO.to(CompanyNecessaryFieldDO.class);
                        CompanyNecessaryFieldVO companyNecessaryFieldVO1 = companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class);
                        companyNecessaryFieldVO1.setEmpTrainListVO(empTrainDO.to(EmpTrainListVO.class));
                        companyNecessaryFieldVOList.add(companyNecessaryFieldVO1);
                    }
                }
                companyEmpNecessaryTrainVOList.add(companyNecessaryFieldVOList);
            }
        }
        companyFieldAndValueListVO.setCompanyEmpNecessaryTrainVOList(companyEmpNecessaryTrainVOList);
        //司员工附件所需信息
        if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工银行所需信息
        if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工员工档案资料所需信息
        if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
        //公司员工离职资料附件所需信息
        if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList())) {
            for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList()) {
                companyNecessaryFieldVO.setEmpInfoVO(empInfoVO);
            }
        }
    }

    private CompanyFieldAndValueListVO addValue(CompanyFieldAndValueListVO companyFieldAndValueListVO, TokenUser tokenUser, String empInfoId) {
        CompanyFieldAndValueListVO result = BeanCopyUtil.beanCopy(companyFieldAndValueListVO, CompanyFieldAndValueListVO.class);

        //基本信息额外字段信息
        if (!CollectionUtils.isEmpty(result.getCompanyAdditionalFieldsBasicVOList())) {
            for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                    result.getCompanyAdditionalFieldsBasicVOList()) {
                EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
                empAdditionalFieldsQuery.setFieldId(companyAdditionalFieldsListVO.getId());
                empAdditionalFieldsQuery.setEmpId(empInfoId);
                List<EmpAdditionalFieldsListVO> empAdditionalFieldsListVOList = empAdditionalFieldsService.select(
                        empAdditionalFieldsQuery, tokenUser.getSiteId());
                if (!CollectionUtils.isEmpty(empAdditionalFieldsListVOList)) {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(
                            empAdditionalFieldsListVOList.get(0).to(EmpAdditionalFieldsVO.class));
                } else {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(null);
                }
            }
        }
        //额外附件所需信息字段
        if (!CollectionUtils.isEmpty(result.getCompanyAdditionalFieldsAttachmentVOList())) {
            for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                    result.getCompanyAdditionalFieldsAttachmentVOList()) {
                EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
                empAdditionalFieldsQuery.setFieldId(companyAdditionalFieldsListVO.getId());
                empAdditionalFieldsQuery.setEmpId(empInfoId);
                List<EmpAdditionalFieldsListVO> empAdditionalFieldsListVOList = empAdditionalFieldsService.select(
                        empAdditionalFieldsQuery, tokenUser.getSiteId());
                if (!CollectionUtils.isEmpty(empAdditionalFieldsListVOList)) {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(
                            empAdditionalFieldsListVOList.get(0).to(EmpAdditionalFieldsVO.class));
                } else {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(null);
                }
            }
        }
        //额外联系所需信息
        if (!CollectionUtils.isEmpty(result.getCompanyAdditionalFieldsContactVOList())) {
            for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                    result.getCompanyAdditionalFieldsContactVOList()) {
                EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
                empAdditionalFieldsQuery.setFieldId(companyAdditionalFieldsListVO.getId());
                empAdditionalFieldsQuery.setEmpId(empInfoId);
                List<EmpAdditionalFieldsListVO> empAdditionalFieldsListVOList = empAdditionalFieldsService.select(
                        empAdditionalFieldsQuery, tokenUser.getSiteId());
                if (!CollectionUtils.isEmpty(empAdditionalFieldsListVOList)) {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(
                            empAdditionalFieldsListVOList.get(0).to(EmpAdditionalFieldsVO.class));
                } else {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(null);
                }
            }
        }
        //员工档案资料
        if (!CollectionUtils.isEmpty(result.getCompanyAdditionalFieldsArchiveVOList())) {
            for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                    result.getCompanyAdditionalFieldsArchiveVOList()) {
                EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
                empAdditionalFieldsQuery.setFieldId(companyAdditionalFieldsListVO.getId());
                empAdditionalFieldsQuery.setEmpId(empInfoId);
                List<EmpAdditionalFieldsListVO> empAdditionalFieldsListVOList = empAdditionalFieldsService.select(
                        empAdditionalFieldsQuery, tokenUser.getSiteId());
                if (!CollectionUtils.isEmpty(empAdditionalFieldsListVOList)) {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(
                            empAdditionalFieldsListVOList.get(0).to(EmpAdditionalFieldsVO.class));
                } else {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(null);
                }
            }
        }
        //员工离职资料
        if (!CollectionUtils.isEmpty(result.getCompanyAdditionalFieldsLeaveOfficeVOList())) {
            for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                    result.getCompanyAdditionalFieldsLeaveOfficeVOList()) {
                EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
                empAdditionalFieldsQuery.setFieldId(companyAdditionalFieldsListVO.getId());
                empAdditionalFieldsQuery.setEmpId(empInfoId);
                List<EmpAdditionalFieldsListVO> empAdditionalFieldsListVOList = empAdditionalFieldsService.select(
                        empAdditionalFieldsQuery, tokenUser.getSiteId());
                if (!CollectionUtils.isEmpty(empAdditionalFieldsListVOList)) {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(
                            empAdditionalFieldsListVOList.get(0).to(EmpAdditionalFieldsVO.class));
                } else {
                    companyAdditionalFieldsListVO.setEmpAdditionalFieldsVO(null);
                }
            }
        }
        return result;
    }

    private void complete(CompanyFieldForPcListVO companyFieldForPcListVO,
                          Map<String, List<CompanyAdditionalFieldsListVO>> companyAdditionalFieldsListMap,
                          Map<String, List<CompanyNecessaryFieldVO>> companyNecessaryFieldMap) {
        for (String key : companyNecessaryFieldMap.keySet()) {
            switch (key) {
                case "annex":
                    companyFieldForPcListVO.setCompanyEmpNecessaryAttachmentVOList(companyNecessaryFieldMap.get(key));
                    companyFieldForPcListVO.setCompanyAdditionalFieldsAttachmentVOList(companyAdditionalFieldsListMap.get(key));
                    break;
                case "socAndPf":
                    companyFieldForPcListVO.setCompanyEmpNecessarySocAndPfVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "bank":
                    companyFieldForPcListVO.setCompanyEmpNecessaryBankVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "basic":
                    companyFieldForPcListVO.setCompanyEmpNecessaryBasicVOList(companyNecessaryFieldMap.get(key));
                    companyFieldForPcListVO.setCompanyAdditionalFieldsBasicVOList(companyAdditionalFieldsListMap.get(key));
                    break;
                case "contact":
                    companyFieldForPcListVO.setCompanyEmpNecessaryContactVOList(companyNecessaryFieldMap.get(key));
                    companyFieldForPcListVO.setCompanyAdditionalFieldsContactVOList(companyAdditionalFieldsListMap.get(key));
                    break;
                case "archive":
                    companyFieldForPcListVO.setCompanyEmpNecessaryArchiveVOList(companyNecessaryFieldMap.get(key));
                    companyFieldForPcListVO.setCompanyAdditionalFieldsArchiveVOList(companyAdditionalFieldsListMap.get(key));
                    break;
                case "leaveOffice":
                    companyFieldForPcListVO.setCompanyEmpNecessaryLeaveOfficeVOList(companyNecessaryFieldMap.get(key));
                    companyFieldForPcListVO.setCompanyAdditionalFieldsLeaveOfficeVOList(companyAdditionalFieldsListMap.get(key));
                    break;
                case "empContacts":
                    companyFieldForPcListVO.setCompanyEmpNecessaryEmergencyContactVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "empEducation":
                    companyFieldForPcListVO.setCompanyEmpNecessaryEducationVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "empFamily":
                    companyFieldForPcListVO.setCompanyEmpNecessaryFamilyMembersVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "empTrain":
                    companyFieldForPcListVO.setCompanyEmpNecessaryTrainVOList(companyNecessaryFieldMap.get(key));
                    break;
                case "empWork":
                    companyFieldForPcListVO.setCompanyEmpNecessaryWorkVOList(companyNecessaryFieldMap.get(key));
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public int selectCount(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, String siteId) {
        Example example = buildExample(companyNecessaryFieldQuery, siteId);
        return companyNecessaryFieldDAO.selectCountByExample(example);
    }

    @Override
    public Page<CompanyNecessaryFieldListVO> selectPage(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, String siteId) {
        Example example = buildExample(companyNecessaryFieldQuery, siteId);
        Page<CompanyNecessaryFieldDO> page = companyNecessaryFieldDAO.selectPageByExample(example,
                companyNecessaryFieldQuery.getPageNo(),
                companyNecessaryFieldQuery.getPageSize());

        return page.to(CompanyNecessaryFieldListVO.class);
    }

    @Override
    public CompanyNecessaryFieldDO selectDOById(String companyNecessaryFieldId, String siteId) {
        return listById(companyNecessaryFieldId, siteId);
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectDOByIds(List<String> companyNecessaryFieldIds, String siteId) {
        if (CollectionUtils.isEmpty(companyNecessaryFieldIds)) {
            return new ArrayList<>();
        }
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", siteId)
                .andEqualTo("isOpen", true)
                .andIn("id", companyNecessaryFieldIds);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectDO(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, String siteId) {
        Example example = buildExample(companyNecessaryFieldQuery, siteId);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public Integer updateNecessaryBatch(CompanyNecessaryFieldBatchDTO companyNecessaryFieldBatchDTO, TokenUser tokenUser) {
        return companyNecessaryFieldDAO.updateNecessaryBatch(companyNecessaryFieldBatchDTO.getCompanyNecessaryFieldUpdateDTOS(),
                new Date(), tokenUser.getUserId());
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public Integer necessaryInitializationByCompanyId(String companyId, TokenUser tokenUser) {
        List<CompanyNecessaryFieldDO> collect = listBySystem();
        if (CollectionUtils.isEmpty(collect)) {
            throw new ParamException("初始化公司员工必填项失败，请先在数据库初始化");
        }
        List<CompanyNecessaryFieldDO> insertList = collect.stream().map(bean -> {
            CompanyNecessaryFieldDO companyNecessaryFieldDO = new CompanyNecessaryFieldDO();
            companyNecessaryFieldDO.setFieldCode(bean.getFieldCode());
            companyNecessaryFieldDO.setFieldName(bean.getFieldName());
            if ("培训单位".equals(bean.getFieldName())) {
                companyNecessaryFieldDO.setIsNecessary(true);
            } else {
                companyNecessaryFieldDO.setIsNecessary(bean.getIsNecessary());
            }
            companyNecessaryFieldDO.setIsOpen(true);
            companyNecessaryFieldDO.setModuleCode(bean.getModuleCode());
            companyNecessaryFieldDO.setModuleName(bean.getModuleName());
            companyNecessaryFieldDO.preInsert(tokenUser.getUserId());
            companyNecessaryFieldDO.setSiteId(tokenUser.getSiteId());
            companyNecessaryFieldDO.setCompanyId(companyId);
            companyNecessaryFieldDO.setFieldType(bean.getFieldType());
            companyNecessaryFieldDO.setSort(bean.getSort());
            companyNecessaryFieldDO.setIsEdit(bean.getIsEdit());
            return companyNecessaryFieldDO;
        }).collect(Collectors.toList());
        return companyNecessaryFieldDAO.insertList(insertList);
    }

    @Override
    public List<CompanyNecessaryFieldDO> listBySystem() {
        Example example = new Example(CompanyEmpNecessaryDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", HrConstants.DEFAULT)
                .andEqualTo("companyId", HrConstants.DEFAULT);
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int initSystemData(TokenUser tokenUser) {
        List<CompanyNecessaryFieldDO> systemList = listBySystem();
        if (!CollectionUtils.isEmpty(systemList)) {
            throw new ParamException("已存在系统默认数据，无需初始化");
        }
        // 创建时间
        Date gmtCreate = new Date();
        List<CompanyNecessaryFieldDO> fieldList = listBySystem();
        if (!CollectionUtils.isEmpty(fieldList)) {
            // 创建必填模块信息
            List<CompanyEmpNecessaryVO> necessaryVOS = companyEmpNecessaryService.selectByCompanyId("2ED7A8589EE84445A0DD63F22CCDBBED", tokenUser);
            for (CompanyEmpNecessaryVO necessaryVO : necessaryVOS) {
                CompanyEmpNecessaryDO necessaryDO = new CompanyEmpNecessaryDO();
                necessaryDO.setCompanyId(HrConstants.DEFAULT);
                necessaryDO.setModuleCode(necessaryVO.getModuleCode());
                necessaryDO.setModuleName(necessaryVO.getModuleName());
                necessaryDO.setIsNecessary(necessaryVO.getIsNecessary());
                necessaryDO.preInsert(HrConstants.DEFAULT);
                necessaryDO.setSiteId(HrConstants.DEFAULT);
                necessaryDO.setCreateUserId(HrConstants.DEFAULT);
                companyEmpNecessaryService.save(necessaryDO);
            }

            // 创建必填字段信息
            List<CompanyNecessaryFieldDO> insertList = fieldList.stream().map(item -> {

                CompanyNecessaryFieldDO companyNecessaryFieldDO = new CompanyNecessaryFieldDO();
                companyNecessaryFieldDO.setFieldCode(item.getFieldCode());
                companyNecessaryFieldDO.setFieldName(item.getFieldName());
                if ("培训单位".equals(item.getFieldName())) {
                    companyNecessaryFieldDO.setIsNecessary(true);
                } else {
                    companyNecessaryFieldDO.setIsNecessary(item.getIsNecessary());
                }
                companyNecessaryFieldDO.setIsOpen(true);
                companyNecessaryFieldDO.setModuleCode(item.getModuleCode());
                companyNecessaryFieldDO.setModuleName(item.getModuleName());
                companyNecessaryFieldDO.preInsert(HrConstants.DEFAULT);
                companyNecessaryFieldDO.setSiteId(HrConstants.DEFAULT);
                companyNecessaryFieldDO.setCompanyId(HrConstants.DEFAULT);
                companyNecessaryFieldDO.setFieldType(item.getFieldType());
                companyNecessaryFieldDO.setSort(item.getSort() * 10);
                companyNecessaryFieldDO.setIsEdit(item.getIsEdit());
                return companyNecessaryFieldDO;
            }).collect(Collectors.toList());

            List<String> codeList = insertList.parallelStream()
                    .map(CompanyNecessaryFieldDO::getFieldCode)
                    .collect(Collectors.toList());
            // 签发机关
            if (!codeList.contains(FIELD_CODE_ISSUEDBY)) {
                CompanyNecessaryFieldDO fieldAddDTO = new CompanyNecessaryFieldDO();
                fieldAddDTO.setSort(611);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_ISSUEDBY);
                fieldAddDTO.setFieldName(FIELD_NAME_ISSUEDBY);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(HrConstants.DEFAULT);
                fieldAddDTO.setGmtCreate(gmtCreate);
                fieldAddDTO.preInsert(HrConstants.DEFAULT);
                fieldAddDTO.setSiteId(HrConstants.DEFAULT);
                insertList.add(fieldAddDTO);
            }
            // 开始期限
            if (!codeList.contains(FIELD_CODE_STARTDATE)) {
                CompanyNecessaryFieldDO fieldAddDTO = new CompanyNecessaryFieldDO();
                fieldAddDTO.setSort(612);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_STARTDATE);
                fieldAddDTO.setFieldName(FIELD_NAME_STARTDATE);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(HrConstants.DEFAULT);
                fieldAddDTO.setGmtCreate(gmtCreate);
                fieldAddDTO.preInsert(HrConstants.DEFAULT);
                fieldAddDTO.setSiteId(HrConstants.DEFAULT);
                insertList.add(fieldAddDTO);
            }
            // 结束期限
            if (!codeList.contains(FIELD_CODE_ENDDATE)) {
                CompanyNecessaryFieldDO fieldAddDTO = new CompanyNecessaryFieldDO();
                fieldAddDTO.setSort(613);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_ENDDATE);
                fieldAddDTO.setFieldName(FIELD_NAME_ENDDATE);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(HrConstants.DEFAULT);
                fieldAddDTO.setGmtCreate(gmtCreate);
                fieldAddDTO.preInsert(HrConstants.DEFAULT);
                fieldAddDTO.setSiteId(HrConstants.DEFAULT);
                insertList.add(fieldAddDTO);
            }
            // 支付宝账号
            if (!codeList.contains(FIELD_CODE_ALIPAY_ACCOUNT)) {
                CompanyNecessaryFieldDO fieldAddDTO = new CompanyNecessaryFieldDO();
                fieldAddDTO.setSort(655);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_ALIPAY_ACCOUNT);
                fieldAddDTO.setFieldName(FIELD_NAME_ALIPAY_ACCOUNT);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_BANK);
                fieldAddDTO.setModuleName(MODULE_NAME_BANK);
                fieldAddDTO.setCompanyId(HrConstants.DEFAULT);
                fieldAddDTO.setGmtCreate(gmtCreate);
                fieldAddDTO.preInsert(HrConstants.DEFAULT);
                fieldAddDTO.setSiteId(HrConstants.DEFAULT);
                insertList.add(fieldAddDTO);
            }
            return companyNecessaryFieldDAO.insertList(insertList);
        }
        return 0;
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int updateBySystemData() {
        // 新建模块数量
        AtomicInteger countModule = new AtomicInteger();
        // 新建字段数量
        AtomicInteger countField = new AtomicInteger();
        // 创建时间
        Date gmtCreate = new Date();

        // 系统默认的必填信息模块
        List<CompanyEmpNecessaryDO> systemEmpNecessaryList = companyEmpNecessaryService.listBySystem();
        // 必填信息模块code集合
        List<String> systemModuleCodeList = systemEmpNecessaryList.parallelStream()
                .map(CompanyEmpNecessaryDO::getModuleCode).collect(Collectors.toList());
        // moduleCode-必填信息模块 Map
        Map<String, CompanyEmpNecessaryDO> moduleCodeNecessaryMap = systemEmpNecessaryList.parallelStream()
                .collect(Collectors.toMap(CompanyEmpNecessaryDO::getModuleCode, v -> v));

        List<CompanyEmpNecessaryDO> companyEmpNecessaryDOS = companyEmpNecessaryService.listAll();
        // 处理必填模块数据
        if (CollectionKit.isNotEmpty(companyEmpNecessaryDOS)) {
            // 查询所有的必填模块，根据用工单位id分组
            Map<String, List<CompanyEmpNecessaryDO>> companyIdNecessaryListMap = companyEmpNecessaryDOS.parallelStream()
                    // 过滤掉系统默认数据
                    .filter(s -> !HrConstants.DEFAULT.equals(s.getCompanyId()))
                    .collect(Collectors.groupingBy(CompanyEmpNecessaryDO::getCompanyId));

            companyIdNecessaryListMap.forEach((companyId, list) -> {
                List<String> itemModuleCodeList = list.parallelStream()
                        .map(CompanyEmpNecessaryDO::getModuleCode).collect(Collectors.toList());
                // 筛选出用工单位中缺失的默认字段
                List<String> systemModuleCodeListCopy = new ArrayList<>(systemModuleCodeList);
                systemModuleCodeListCopy.removeAll(itemModuleCodeList);
                if (CollectionKit.isNotEmpty(systemModuleCodeListCopy)) {
                    String siteId = list.get(0).getSiteId();
                    String userId = list.get(0).getCreateUserId();
                    for (String moduleCode : systemModuleCodeListCopy) {
                        CompanyEmpNecessaryDO itemNecessaryDO = moduleCodeNecessaryMap.get(moduleCode);
                        if (Objects.nonNull(itemNecessaryDO)) {
                            CompanyEmpNecessaryDO necessaryDO = new CompanyEmpNecessaryDO();
                            necessaryDO.setModuleName(itemNecessaryDO.getModuleName());
                            necessaryDO.setModuleCode(itemNecessaryDO.getModuleCode());
                            necessaryDO.setIsNecessary(itemNecessaryDO.getIsNecessary());
                            necessaryDO.setCompanyId(companyId);
                            necessaryDO.setGmtCreate(gmtCreate);
                            // 为用工单位添加缺失的模块
                            companyEmpNecessaryService.save(necessaryDO, siteId, userId);
                            countModule.getAndIncrement();
                            log.info("新建模块：companyId：{}，moduleCode：{}，moduleName：{}", companyId, moduleCode,
                                    itemNecessaryDO.getModuleName());
                        }
                    }
                }
            });
        }
        log.info("新建{}条模块记录", countModule);

        // 校验字段时用 moduleCode-fieldCode作为数据的唯一key
        // 系统默认的字段
        List<CompanyNecessaryFieldDO> systemFieldList = listBySystem();
        // moduleCode-fieldCode 集合
        List<String> systemFieldCodeList = systemFieldList.parallelStream()
                .map(s -> s.getModuleCode() + "-" + s.getFieldCode()).collect(Collectors.toList());
        // moduleCode-fieldCode-字段 Map
        Map<String, CompanyNecessaryFieldDO> fieldCodeNecessaryMap = systemFieldList.parallelStream()
                .collect(Collectors.toMap(s -> s.getModuleCode() + "-" + s.getFieldCode(), v -> v));

        List<CompanyNecessaryFieldDO> necessaryFieldDOS = listAll();
        if (CollectionKit.isNotEmpty(necessaryFieldDOS)) {
            // 查询所有的模块字段，根据用工单位id分组
            Map<String, List<CompanyNecessaryFieldDO>> companyIdFieldListMap = necessaryFieldDOS.parallelStream()
                    // 过滤掉系统默认数据
                    .filter(s -> !HrConstants.DEFAULT.equals(s.getCompanyId()))
                    .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getCompanyId));

            companyIdFieldListMap.forEach((companyId, list) -> {
                List<String> itemFieldCodeList = list.parallelStream()
                        .map(s -> s.getModuleCode() + "-" + s.getFieldCode()).collect(Collectors.toList());
                // 筛选出用工单位中缺失的默认字段
                List<String> systemFieldCodeListCopy = new ArrayList<>(systemFieldCodeList);
                systemFieldCodeListCopy.removeAll(itemFieldCodeList);
                if (CollectionKit.isNotEmpty(systemFieldCodeListCopy)) {
                    String siteId = list.get(0).getSiteId();
                    String userId = list.get(0).getCreateUserId();
                    for (String fieldCode : systemFieldCodeListCopy) {
                        CompanyNecessaryFieldDO itemFieldDO = fieldCodeNecessaryMap.get(fieldCode);
                        if (Objects.nonNull(itemFieldDO)) {
                            CompanyNecessaryFieldDO necessaryFieldDO = new CompanyNecessaryFieldDO();
                            necessaryFieldDO.setSort(itemFieldDO.getSort());
                            necessaryFieldDO.setIsEdit(itemFieldDO.getIsEdit());
                            necessaryFieldDO.setFieldType(itemFieldDO.getFieldType());
                            necessaryFieldDO.setFieldCode(itemFieldDO.getFieldCode());
                            necessaryFieldDO.setFieldName(itemFieldDO.getFieldName());
                            necessaryFieldDO.setIsNecessary(itemFieldDO.getIsNecessary());
                            necessaryFieldDO.setIsOpen(itemFieldDO.getIsOpen());
                            necessaryFieldDO.setModuleName(itemFieldDO.getModuleName());
                            necessaryFieldDO.setModuleCode(itemFieldDO.getModuleCode());
                            necessaryFieldDO.setCompanyId(companyId);
                            necessaryFieldDO.setGmtCreate(gmtCreate);
                            save(necessaryFieldDO, siteId, userId);
                            countField.getAndIncrement();
                            log.info("新建字段：companyId：{}，moduleCode：{}，moduleName：{}，fieldCode：{}，fieldName：{}，",
                                    companyId, itemFieldDO.getModuleCode(), itemFieldDO.getModuleName(),
                                    itemFieldDO.getFieldCode(), itemFieldDO.getFieldName());
                        }
                    }
                }
            });
        }
        log.info("新建{}条字段记录", countField);
        return countField.get();
    }


    @Override
    public String findNotCompleteUpdate(CompanyFieldAndValueListVO companyFieldAndValueListVO, String type, String companyId, TokenUser tokenUser) {
        Example example = new Example(CompanyEmpNecessaryDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", tokenUser.getSiteId())
                .andEqualTo("companyId", companyId);
        String needCompleteThing = "";
        switch (type) {
            case "annex":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryAttachmentVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "bank":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryBankVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "socAndPf":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessarySocAndPfVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessarySocAndPfVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessarySocAndPfVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "basic":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryBasicVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "contact":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryContactVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "archive":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryArchiveVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "leaveOffice":
                if (CollectionKit.isNotEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList())) {
                    for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList()) {
                        //必填
                        if (companyNecessaryFieldVO.getIsNecessary()) {
                            //是否为空
                            String s = ClassKit.getValue(companyNecessaryFieldVO.getEmpInfoVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                            if ("".equals(s) || "null".equals(s)) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                }
                            }
                        }
                    }
                }
                if (!"".equals(needCompleteThing)) {
                    needCompleteThing =
                            companyFieldAndValueListVO.getCompanyEmpNecessaryLeaveOfficeVOList().get(0).getModuleName() +
                                    "-" + needCompleteThing;
                }
                break;
            case "empContacts":
                if (CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryEmergencyContactVOList())) {
                    example.and().andEqualTo("moduleCode", "empContacts");
                    CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDAO.selectOneByExample(example);
                    if (companyEmpNecessaryDO.getIsNecessary()) {
                        Example exampleField = new Example(CompanyNecessaryFieldDO.class);
                        exampleField.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("moduleCode", "empContacts");
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldDAO.selectByExample(exampleField);
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                            if (companyNecessaryFieldDO.getIsNecessary()) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldDO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldDO.getFieldName();
                                }
                            } else {
                                continue;
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldDOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    } else {
                        break;
                    }
                } else {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryEmergencyContactVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            //必填
                            if (companyNecessaryFieldVO.getIsNecessary()) {
                                //是否为空
                                String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpContactsListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                                if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                    if ("".equals(needCompleteThing)) {
                                        needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                    } else {
                                        needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                    }
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldVOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    }
                }

                break;
            case "empEducation":
                if (CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList())) {
                    example.and().andEqualTo("moduleCode", "empEducation");
                    CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDAO.selectOneByExample(example);
                    if (companyEmpNecessaryDO.getIsNecessary()) {
                        Example exampleField = new Example(CompanyNecessaryFieldDO.class);
                        exampleField.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("moduleCode", "empEducation");
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldDAO.selectByExample(exampleField);
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                            if (companyNecessaryFieldDO.getIsNecessary()) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldDO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldDO.getFieldName();
                                }
                            } else {
                                continue;
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldDOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    } else {
                        break;
                    }
                } else {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryEducationVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            //必填
                            if (companyNecessaryFieldVO.getIsNecessary()) {
                                //是否为空
                                String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpEducationVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                                if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                    if ("".equals(needCompleteThing)) {
                                        needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                    } else {
                                        needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                    }
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldVOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    }
                }

                break;
            case "empFamily":
                if (CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryFamilyMembersVOList())) {
                    example.and().andEqualTo("moduleCode", "empFamily");
                    CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDAO.selectOneByExample(example);
                    if (companyEmpNecessaryDO.getIsNecessary()) {
                        Example exampleField = new Example(CompanyNecessaryFieldDO.class);
                        exampleField.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("moduleCode", "empFamily");
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldDAO.selectByExample(exampleField);
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                            if (companyNecessaryFieldDO.getIsNecessary()) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldDO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldDO.getFieldName();
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldDOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    } else {
                        break;
                    }
                } else {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryFamilyMembersVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            //必填
                            if (companyNecessaryFieldVO.getIsNecessary()) {
                                //是否为空
                                String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpFamilyVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                                if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                    if ("".equals(needCompleteThing)) {
                                        needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                    } else {
                                        needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                    }
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldVOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    }
                }
                break;
            case "empTrain":
                if (CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryTrainVOList())) {
                    example.and().andEqualTo("moduleCode", "empTrain");
                    CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDAO.selectOneByExample(example);
                    if (companyEmpNecessaryDO.getIsNecessary()) {
                        Example exampleField = new Example(CompanyNecessaryFieldDO.class);
                        exampleField.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("moduleCode", "empTrain");
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldDAO.selectByExample(exampleField);
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                            if (companyNecessaryFieldDO.getIsNecessary()) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldDO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldDO.getFieldName();
                                }
                            } else {
                                continue;
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldDOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    } else {
                        break;
                    }
                } else {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryTrainVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            //必填
                            if (companyNecessaryFieldVO.getIsNecessary()) {
                                //是否为空
                                String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpTrainListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                                if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                    if ("".equals(needCompleteThing)) {
                                        needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                    } else {
                                        needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                    }
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldVOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    }
                }
                break;
            case "empWork":
                if (CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyEmpNecessaryWorkVOList())) {
                    example.and().andEqualTo("moduleCode", "empWork");
                    CompanyEmpNecessaryDO companyEmpNecessaryDO = companyEmpNecessaryDAO.selectOneByExample(example);
                    if (companyEmpNecessaryDO.getIsNecessary()) {
                        Example exampleField = new Example(CompanyNecessaryFieldDO.class);
                        exampleField.and()
                                .andEqualTo("valid", true)
                                .andEqualTo("companyId", companyId)
                                .andEqualTo("moduleCode", "empWork");
                        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldDAO.selectByExample(exampleField);
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : companyNecessaryFieldDOList) {
                            if (companyNecessaryFieldDO.getIsNecessary()) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyNecessaryFieldDO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldDO.getFieldName();
                                }
                            } else {
                                continue;
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldDOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    } else {
                        break;
                    }
                } else {
                    for (List<CompanyNecessaryFieldVO> companyNecessaryFieldVOList :
                            companyFieldAndValueListVO.getCompanyEmpNecessaryWorkVOList()) {
                        for (CompanyNecessaryFieldVO companyNecessaryFieldVO : companyNecessaryFieldVOList) {
                            //必填
                            if (companyNecessaryFieldVO.getIsNecessary()) {
                                //是否为空
                                String empFamilyString = ClassKit.getValue(companyNecessaryFieldVO.getEmpWorkListVO(), companyNecessaryFieldVO.getFieldCode()) + "";
                                if ("".equals(empFamilyString) || "null".equals(empFamilyString)) {
                                    if ("".equals(needCompleteThing)) {
                                        needCompleteThing = companyNecessaryFieldVO.getFieldName();
                                    } else {
                                        needCompleteThing = needCompleteThing + "-" + companyNecessaryFieldVO.getFieldName();
                                    }
                                }
                            }
                        }
                        if (!"".equals(needCompleteThing)) {
                            needCompleteThing = companyNecessaryFieldVOList.get(0).getModuleName() + "-" + needCompleteThing;
                        }
                    }
                }
                break;
            default:
                break;
        }
        return needCompleteThing;
    }

    /**
     * 额外字段信息的修改
     *
     * @param companyFieldAndValueListVO 额外字段信息
     * @param type                       类型
     * @return 失败字段
     */
    @Override
    public String findNotCompleteAdditional(CompanyFieldAndValueListVO companyFieldAndValueListVO, String type) {
        String needCompleteThing = "";
        switch (type) {
            case "annex":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsAttachmentVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsAttachmentVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyAdditionalFieldsListVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyAdditionalFieldsListVO.getFieldName();
                                }
                            }
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        needCompleteThing = "员工额外资料模块-" + needCompleteThing;
                    }
                }
                break;
            case "basic":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsBasicVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsBasicVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyAdditionalFieldsListVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyAdditionalFieldsListVO.getFieldName();
                                }
                            }
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        needCompleteThing = "员工基本资料模块-" + needCompleteThing;
                    }
                }
                break;
            case "contact":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsContactVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsContactVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyAdditionalFieldsListVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyAdditionalFieldsListVO.getFieldName();
                                }
                            }
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        needCompleteThing = "员工联系人模块-" + needCompleteThing;
                    }
                }
                break;
            case "archive":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsArchiveVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsArchiveVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyAdditionalFieldsListVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyAdditionalFieldsListVO.getFieldName();
                                }
                            }
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        needCompleteThing = "员工档案资料所需信息-" + needCompleteThing;
                    }
                }
                break;
            case "leaveOffice":
                if (!CollectionUtils.isEmpty(companyFieldAndValueListVO.getCompanyAdditionalFieldsLeaveOfficeVOList())) {
                    for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO :
                            companyFieldAndValueListVO.getCompanyAdditionalFieldsLeaveOfficeVOList()) {
                        if (companyAdditionalFieldsListVO.getIsNecessary()) {
                            if (companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO() == null ||
                                    StringUtils.isEmpty(companyAdditionalFieldsListVO.getEmpAdditionalFieldsVO().getContent())) {
                                if ("".equals(needCompleteThing)) {
                                    needCompleteThing = companyAdditionalFieldsListVO.getFieldName();
                                } else {
                                    needCompleteThing = needCompleteThing + "-" + companyAdditionalFieldsListVO.getFieldName();
                                }
                            }
                        }
                    }
                    if (!"".equals(needCompleteThing)) {
                        needCompleteThing = "员工离职资料附件所需信息-" + needCompleteThing;
                    }
                }
                break;
            default:
                break;
        }
        return needCompleteThing;
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectByModuleCode(String moduleCode, String companyId, String siteId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", siteId)
                .andEqualTo("companyId", companyId)
                .andEqualTo("moduleCode", moduleCode);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectByCompanyId(String companyId, String siteId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", siteId)
                .andEqualTo("companyId", companyId);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectCompanyAllNeedCheckField(String companyId, String siteId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", siteId)
                .andEqualTo("isOpen", Boolean.TRUE)
                .andEqualTo("isNecessary", Boolean.TRUE)
                .andEqualTo("companyId", companyId);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public void checkInAddNecessaryField(String companyId, TokenUser tokenUser) {
        // 查询必填模块
        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOList = companyEmpNecessaryService.selectByCompanyId(companyId, tokenUser);
        if (CollectionUtils.isEmpty(companyEmpNecessaryVOList)) {
            // 初始化员工设置
            necessaryInitializationByCompanyId(companyId, tokenUser);
        }
        companyEmpNecessaryVOList = companyEmpNecessaryService.selectByCompanyId(companyId, tokenUser);
        Map<String, List<CompanyEmpNecessaryVO>> codeListMap = companyEmpNecessaryVOList.parallelStream()
                .collect(Collectors.groupingBy(CompanyEmpNecessaryVO::getModuleCode));
        List<CompanyEmpNecessaryVO> companyEmpNecessaryVOS = codeListMap.get(MODULE_CODE_EMPIDCARD);
        // 如果没有身份证信息模块，新增
        if (CollectionUtils.isEmpty(companyEmpNecessaryVOS)) {
            CompanyEmpNecessaryAddDTO necessaryAddDTO = new CompanyEmpNecessaryAddDTO();
            necessaryAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
            necessaryAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
            necessaryAddDTO.setIsNecessary(false);
            necessaryAddDTO.setCompanyId(companyId);
            CompanyEmpNecessaryVO save = companyEmpNecessaryService.save(necessaryAddDTO, tokenUser);
        }
        // 查询必填字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = selectByCompanyId(companyId, tokenUser.getSiteId());
        if (CollectionUtils.isEmpty(companyNecessaryFieldDOList)) {
            // 初始化员工设置
            necessaryInitializationByCompanyId(companyId, tokenUser);
        } else {
            List<String> codeList = companyNecessaryFieldDOList.parallelStream()
                    .map(CompanyNecessaryFieldDO::getFieldCode)
                    .collect(Collectors.toList());
            // 签发机关
            if (!codeList.contains(FIELD_CODE_ISSUEDBY)) {
                CompanyNecessaryFieldAddDTO fieldAddDTO = new CompanyNecessaryFieldAddDTO();
                fieldAddDTO.setSort(10);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_ISSUEDBY);
                fieldAddDTO.setFieldName(FIELD_NAME_ISSUEDBY);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(companyId);

                save(fieldAddDTO, tokenUser);
            }
            // 开始期限
            if (!codeList.contains(FIELD_CODE_STARTDATE)) {
                CompanyNecessaryFieldAddDTO fieldAddDTO = new CompanyNecessaryFieldAddDTO();
                fieldAddDTO.setSort(20);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_STARTDATE);
                fieldAddDTO.setFieldName(FIELD_NAME_STARTDATE);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(companyId);

                save(fieldAddDTO, tokenUser);
            }
            // 结束期限
            if (!codeList.contains(FIELD_CODE_ENDDATE)) {
                CompanyNecessaryFieldAddDTO fieldAddDTO = new CompanyNecessaryFieldAddDTO();
                fieldAddDTO.setSort(30);
                fieldAddDTO.setIsEdit(1);
                fieldAddDTO.setFieldType("2");
                fieldAddDTO.setFieldCode(FIELD_CODE_ENDDATE);
                fieldAddDTO.setFieldName(FIELD_NAME_ENDDATE);
                fieldAddDTO.setIsNecessary(false);
                fieldAddDTO.setIsOpen(true);
                fieldAddDTO.setModuleCode(MODULE_CODE_EMPIDCARD);
                fieldAddDTO.setModuleName(MODULE_NAME_EMPIDCARD);
                fieldAddDTO.setCompanyId(companyId);

                save(fieldAddDTO, tokenUser);
            }
        }
    }

    @Override
    public List<CompanyNecessaryFieldDO> selectByCompanyAndModuleCodes(String companyId, List<String> moduleCodes, String siteId) {
        if (CollectionUtils.isEmpty(moduleCodes)) {
            return new ArrayList<>();
        }
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("companyId", companyId)
                .andEqualTo("isOpen", true)
                .andIn("moduleCode", moduleCodes)
                .andEqualTo("isOpen", true)
                .andEqualTo("siteId", siteId);
        example.orderBy("sort");
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    @Override
    public List<CompanyNecessaryFieldDO> listAll() {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true);
        return companyNecessaryFieldDAO.selectByExample(example);
    }

    /**
     * 根据查询参数，构建example
     *
     * @param companyNecessaryFieldQuery 查询参数
     * @param siteId                     所属站点id
     * @return example
     */
    private Example buildExample(CompanyNecessaryFieldQuery companyNecessaryFieldQuery, String siteId) {
        Example example = new Example(CompanyNecessaryFieldDO.class);
        example.and()
                .andEqualTo("valid", true)
                .andEqualTo("siteId", siteId);
        if (companyNecessaryFieldQuery.getSort() != null) {
            example.and().andEqualTo("sort", companyNecessaryFieldQuery.getSort());
        }
        if (companyNecessaryFieldQuery.getIsEdit() != null) {
            example.and().andEqualTo("isEdit", companyNecessaryFieldQuery.getIsEdit());
        }
        if (companyNecessaryFieldQuery.getFieldType() != null) {
            example.and().andEqualTo("fieldType", companyNecessaryFieldQuery.getFieldType());
        }
        if (companyNecessaryFieldQuery.getFieldCode() != null) {
            example.and().andEqualTo("fieldCode", companyNecessaryFieldQuery.getFieldCode());
        }
        if (companyNecessaryFieldQuery.getFieldName() != null) {
            example.and().andLike("fieldName", "%" + companyNecessaryFieldQuery.getFieldName() + "%");
        }
        if (companyNecessaryFieldQuery.getIsNecessary() != null) {
            example.and().andEqualTo("isNecessary", companyNecessaryFieldQuery.getIsNecessary());
        }
        if (companyNecessaryFieldQuery.getIsOpen() != null) {
            example.and().andEqualTo("isOpen", companyNecessaryFieldQuery.getIsOpen());
        }
        if (companyNecessaryFieldQuery.getModuleName() != null) {
            example.and().andEqualTo("moduleName", companyNecessaryFieldQuery.getModuleName());
        }
        if (companyNecessaryFieldQuery.getModuleCode() != null) {
            example.and().andEqualTo("moduleCode", companyNecessaryFieldQuery.getModuleCode());
        }
        if (companyNecessaryFieldQuery.getCompanyId() != null) {
            example.and().andEqualTo("companyId", companyNecessaryFieldQuery.getCompanyId());
        }
        // 排序
        ExampleKit.setExampleOrder(example, companyNecessaryFieldQuery.getOrders());
        return example;
    }

    @Override
    public List<HeaderFieldsListVO> getCustomField(String companyId, TokenUser tokenUser) {
        String[] strings = {"basic", "contact", "empFamily", "empContacts", "empEducation",
                "empWork", "empTrain", "empIdCard", "empState", "onJob", "file", "retire"};
        List<String> codeList = Arrays.asList(strings);
        List<HeaderFieldsListVO> headerFieldsListVOList = new ArrayList<>();
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectByCompanyId2(companyId, null, tokenUser.getSiteId());
        companyAdditionalFieldsListVOList = companyAdditionalFieldsListVOList.stream().filter(p -> codeList.contains(p.getModuleCode())).filter(CompanyAdditionalFieldsListVO::getIsOpen).collect(Collectors.toList());
        for (CompanyAdditionalFieldsListVO companyAdditionalFieldsListVO : companyAdditionalFieldsListVOList) {
            headerFieldsListVOList.add(companyAdditionalFieldsListVO.to(HeaderFieldsListVO.class));
        }
        //查询所有花名册表头字段
        HeaderFieldsQuery headerFieldsQuery = new HeaderFieldsQuery();
        if ("site".equals(companyId)) {
            headerFieldsQuery.setModuleCode("empInfo");
        } else {
            headerFieldsQuery.setModuleCode("empInfoByCompany");
            headerFieldsQuery.setSubjectId(companyId);
        }
        headerFieldsQuery.setCreateUserId(tokenUser.getUserId());
        List<HeaderFieldsListVO> headField = adminProviderService.getHeadField(headerFieldsQuery, tokenUser);
        headField = headField.parallelStream().filter(headerFieldsListVO -> !headerFieldsListVO.getIsFix()).collect(Collectors.toList());
        for (HeaderFieldsListVO headerFieldsListVO : headField) {
            headerFieldsListVOList.removeIf(next -> next.getId().equals(headerFieldsListVO.getFieldEnName()));
        }
        headerFieldsListVOList.forEach(headerFieldsListVO -> headerFieldsListVO.setIsFix(false));
        return headerFieldsListVOList;
    }

    @Override
    @Transactional(value = HrConstants.TX, rollbackFor = Exception.class)
    public int addAllCompanyFields(String yourName, List<CompanyNecessaryFieldAddDTO> companyNecessaryFieldAddDTOList) {
        // 已存在的同名字段
        List<String> fieldNames = companyNecessaryFieldAddDTOList.parallelStream()
                .map(CompanyNecessaryFieldAddDTO::getFieldName).distinct().collect(Collectors.toList());
        List<CompanyNecessaryFieldDO> hadList = selectByFiledNames(fieldNames);
        // 已存在的同名字段 按用工单位分组
        Map<String, List<CompanyNecessaryFieldDO>> companyIdListMap = hadList.parallelStream()
                .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getCompanyId));
        int companyNum = 0;
        // 初始化各个用工单位的同时 初始化租户
        Map<String, SiteDO> siteMap = adminProviderService.selectSiteMap();
        for (String siteId : siteMap.keySet()) {
            List<CompanyDO> companyDOList = companyService.selectBySiteId(siteId);
            if (CollectionUtils.isEmpty(companyDOList)) {
                companyDOList = new ArrayList<>();
            }
            CompanyDO siteCompanyDO = new CompanyDO();
            siteCompanyDO.setId("site");
            companyDOList.add(siteCompanyDO);
            companyNum += companyDOList.size();
            // 所有用工单位新增
            List<CompanyNecessaryFieldAddDTO> companyNecessaryFieldAddList = new ArrayList<>();
            for (CompanyDO companyDO : companyDOList) {
                String companyDOId = companyDO.getId();
                // 用工单位存在的同名字段
                List<CompanyNecessaryFieldDO> companyHadList = companyIdListMap.get(companyDOId);
                if (CollectionUtils.isEmpty(companyHadList)) {
                    companyHadList = new ArrayList<>();
                }
                if ("site".equals(companyDOId)) {
                    companyHadList = companyHadList.parallelStream().filter(companyNecessaryFieldDO ->
                            siteId.equals(companyNecessaryFieldDO.getSiteId())).collect(Collectors.toList());
                }
                Map<String, List<CompanyNecessaryFieldDO>> fieldNameListMap = new HashMap<>();
                if (!CollectionUtils.isEmpty(companyHadList)) {
                    // 已存在的同名字段 按名称分组
                    fieldNameListMap = companyHadList.parallelStream()
                            .collect(Collectors.groupingBy(CompanyNecessaryFieldDO::getFieldName));
                }
                for (CompanyNecessaryFieldAddDTO companyNecessaryFieldAddDTO : companyNecessaryFieldAddDTOList) {
                    // 需要添加
                    boolean needAdd = true;
                    List<CompanyNecessaryFieldDO> fieldNameList = fieldNameListMap.get(companyNecessaryFieldAddDTO.getFieldName());
                    if (!CollectionUtils.isEmpty(fieldNameList)) {
                        for (CompanyNecessaryFieldDO companyNecessaryFieldDO : fieldNameList) {
                            // 用工单位、字段名、模块code都一样 判断为同一字段
                            if (companyNecessaryFieldDO.getModuleCode().equals(companyNecessaryFieldAddDTO.getModuleCode())) {
                                CompanyNecessaryFieldUpdateDTO companyNecessaryFieldUpdateDTO
                                        = companyNecessaryFieldAddDTO.to(CompanyNecessaryFieldUpdateDTO.class);
                                companyNecessaryFieldUpdateDTO.setCompanyId(companyDOId);
                                companyNecessaryFieldUpdateDTO.setId(companyNecessaryFieldDO.getId());
                                TokenUser tokenUser = new TokenUser();
                                SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
                                tokenUser.setUserId(yourName + formatter.format(new Date()));
                                tokenUser.setSiteId(companyNecessaryFieldDO.getSiteId());
                                update(companyNecessaryFieldUpdateDTO, tokenUser);
                                needAdd = false;
                                break;
                            }
                        }
                    }
                    if (needAdd) {
                        CompanyNecessaryFieldAddDTO necessaryFieldAddDTO = companyNecessaryFieldAddDTO
                                .to(companyNecessaryFieldAddDTO.getClass());
                        necessaryFieldAddDTO.setCompanyId(companyDOId);
                        companyNecessaryFieldAddList.add(necessaryFieldAddDTO);
                    }
                }
            }
            TokenUser tokenUser = new TokenUser();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
            tokenUser.setUserId(yourName + formatter.format(new Date()));
            tokenUser.setSiteId(siteId);
            batchSave(companyNecessaryFieldAddList, tokenUser);
        }
        return companyNum * companyNecessaryFieldAddDTOList.size();
    }

    @Override
    public List<CompanyNecessaryModuleCodeVO> listCompanyModuleCodesForEmployee(
            CompanyNecessaryFieldQuery companyNecessaryFieldQuery, TokenUser tokenUser) {
        List<CompanyNecessaryModuleCodeVO> companyNecessaryModuleCodeList = new ArrayList<>();
        //查询moduleCode是否必填
        //因为是员工端查询，应该看不到 员工状态、在职信息、档案信息、奖惩记录、退休信息
        List<CompanyEmpNecessaryVO> moduleCodeTempList = companyEmpNecessaryService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser);
        Map<String, CompanyEmpNecessaryVO> moduleNecessaryMap = moduleCodeTempList.stream()
                .collect(Collectors.toMap(CompanyEmpNecessaryVO::getModuleCode, Function.identity()));
        //模块下的所有字段
        List<CompanyNecessaryFieldDO> companyNecessaryFieldList = this.selectDO(companyNecessaryFieldQuery, tokenUser.getSiteId());

        //所有字段根据moduleCode分组
        Map<String, List<CompanyNecessaryFieldVO>> moduleFieldListMap = companyNecessaryFieldList.stream()
                //只查指定分类的moduleCode
                .filter(companyNecessaryFieldDO -> EmpFieldModuleCodeKit.isModuleTypeInTypeList(companyNecessaryFieldQuery.getType(), companyNecessaryFieldDO.getModuleCode()))
                .filter(CompanyNecessaryFieldDO::getIsOpen)
                .map(companyNecessaryFieldDO -> companyNecessaryFieldDO.to(CompanyNecessaryFieldVO.class))
                .collect(Collectors.groupingBy(CompanyNecessaryFieldVO::getModuleCode));
        //查询所有自定义字段
        List<CompanyAdditionalFieldsListVO> companyAdditionalFieldsListVOList =
                companyAdditionalFieldsService.selectByCompanyId(companyNecessaryFieldQuery.getCompanyId(), tokenUser.getSiteId());
        //所有自定义字段根据moduleCode分组
        Map<String, List<CompanyAdditionalFieldsListVO>> additionalFieldMap = companyAdditionalFieldsListVOList.stream()
                .collect(Collectors.groupingBy(CompanyAdditionalFieldsListVO::getModuleCode));
        List<String> moduleCodeList = EmpFieldModuleCodeKit.getAllModuleCodeList();
        List<String> excludeModule = new ArrayList<>();
        excludeModule.add("empState");
        excludeModule.add("onJob");
        excludeModule.add("file");
        excludeModule.add("rewardsPunishments");
        excludeModule.add("retire");
        moduleCodeList.removeAll(excludeModule);
        moduleCodeList.forEach(moduleCode -> {
            CompanyNecessaryModuleCodeVO companyNecessaryModuleCodeVO = new CompanyNecessaryModuleCodeVO();
            companyNecessaryModuleCodeVO.setModuleCode(moduleCode);
            companyNecessaryModuleCodeVO.setModuleName(EmpFieldModuleCodeKit.getModuleCodeZhName(moduleCode));
            companyNecessaryModuleCodeVO.setNecessary(EmpFieldModuleCodeKit.getModuleCodeNecessary(moduleCode));
            //必填还由员工设置确定
            CompanyEmpNecessaryVO companyEmpNecessaryVO = moduleNecessaryMap.get(moduleCode);
            if (companyEmpNecessaryVO != null) {
                companyNecessaryModuleCodeVO.setNecessary(companyEmpNecessaryVO.getIsNecessary());
            }
            //填写信息为多条
            companyNecessaryModuleCodeVO.setMultiple(EmpFieldModuleCodeKit.getModuleCodeSupportNecessary(moduleCode));
            //组装字段
            List<CompanyNecessaryFieldVO> fieldList = moduleFieldListMap.get(moduleCode);
            if (CollectionUtils.isEmpty(fieldList)) {
                fieldList = new ArrayList<>();
            }

            EmpFieldModuleCodeKit.setFieldGroupName(fieldList);
            //设置字段的下拉选项数组
            EmpFieldModuleCodeKit.setFieldDropDownArray(companyNecessaryFieldQuery.getCompanyId(), fieldList, moduleCode, tokenUser.getSiteId());
            setPostType(fieldList, tokenUser);
            if ("员工状态".equals(companyNecessaryModuleCodeVO.getModuleName())) {
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    if ("转正日期".equals(companyNecessaryFieldVO.getFieldName())
                            || "司龄".equals(companyNecessaryFieldVO.getFieldName())) {
                        companyNecessaryFieldVO.setIsDisabled(Boolean.TRUE);
                    }
                }
            } else if ("在职信息".equals(companyNecessaryModuleCodeVO.getModuleName())) {
                for (CompanyNecessaryFieldVO companyNecessaryFieldVO : fieldList) {
                    if ("录入人".equals(companyNecessaryFieldVO.getFieldName())
                            || "录入方式".equals(companyNecessaryFieldVO.getFieldName())) {
                        companyNecessaryFieldVO.setIsDisabled(Boolean.TRUE);
                    }
                }
            }
            companyNecessaryModuleCodeVO.setFieldList(fieldList);
            //组装自定义字段
            List<CompanyAdditionalFieldsListVO> additionalFieldList = additionalFieldMap.get(moduleCode);
            if (additionalFieldList != null) {
                //自定义字段的英文名为id
                additionalFieldList.forEach(companyAdditionalFieldsListVO ->
                        companyAdditionalFieldsListVO.setFieldCode(SafeKit.getString(companyAdditionalFieldsListVO.getId())));
            }
            companyNecessaryModuleCodeVO.setAdditionalFieldList(additionalFieldList == null ? new ArrayList<>() : additionalFieldList);
            companyNecessaryModuleCodeList.add(companyNecessaryModuleCodeVO);
            if (!"家庭成员".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"紧急联系人".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"教育经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"工作经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !"培训经历".equals(companyNecessaryModuleCodeVO.getModuleName())
                    && !CollectionUtils.isEmpty(companyNecessaryModuleCodeVO.getFieldList())) {
                companyNecessaryModuleCodeVO.setNecessary(companyNecessaryModuleCodeVO.getFieldList()
                        .parallelStream().anyMatch(CompanyNecessaryFieldVO::getIsNecessary));
            }
        });
        return companyNecessaryModuleCodeList;
    }

    @Override
    public Map<String, EmpFieldValueVO> getAllEmpFieldValue(ModuleFieldQuery moduleFieldQuery, TokenUser tokenUser) {
        List<String> list = moduleFieldQuery.getModuleCodeList();
        Map<String, EmpFieldValueVO> result = new HashMap<>();
        if (!CollectionUtils.isEmpty(list)) {
            StopWatch sw = new StopWatch("getAllEmpFieldValue");
            sw.start("字段分组，异步查询");
            List<Future<Map<String, EmpFieldValueVO>>> temp = new ArrayList<>();
            for (String moduleCode : list) {
                ModuleFieldQuery param = new ModuleFieldQuery();
                param.setCompanyId(moduleFieldQuery.getCompanyId());
                param.setModuleCode(moduleCode);
                param.setEmpInfoId(moduleFieldQuery.getEmpInfoId());
                //采用异步方式，查询字段分组下的字段
                Future<Map<String, EmpFieldValueVO>> map = asyncEmpInfoDetailService.getEmpFieldValue(param, tokenUser);
                temp.add(map);
            }
            sw.stop();
            sw.start("字段分组，同步获取结果");
            for (Future<Map<String, EmpFieldValueVO>> mapFuture : temp) {
                try {
                    Map<String, EmpFieldValueVO> fieldMap = mapFuture.get();
                    result.putAll(fieldMap);
                } catch (Exception e) {
                    log.error("查询字段分组异常", e);
                }
            }
            sw.stop();
            log.info(sw.prettyPrint());
        }
        return result;
    }
}
